summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2019-09-03 19:31:14 +0800
committeryangwei <[email protected]>2019-09-03 19:31:14 +0800
commit49b73ccecb2b86fb84efe9672d699d4bb51b217a (patch)
tree38d96d8c41a828101f51fb2b8542e1563de5d9ef
parentace638519716da065ae7ec3a1cb0e6fc884019ab (diff)
parent834e7ef0790d7f51ff96fc893280ca71969ed78f (diff)
Merge branch 'pangu_develop_parallel'
# Conflicts: # CMakeLists.txt # run/conf/main.conf
-rw-r--r--.gitignore5
-rw-r--r--CMakeLists.txt124
-rw-r--r--dealpkt/callapp.c1864
-rw-r--r--dealpkt/deal_ethernet.c496
-rw-r--r--dealpkt/deal_tcp.c8
-rw-r--r--dealpkt/deal_vlan.c450
-rw-r--r--dealpkt/stream_manage.c4
-rw-r--r--entry/CMakeLists.txt28
-rw-r--r--entry/sapp_init.c8
-rw-r--r--include/stream_internal.h5
-rw-r--r--include/sysinfo.h297
-rw-r--r--inner_plug/CMakeLists.txt2
-rw-r--r--inner_plug/sapp_assistant.cpp99
-rw-r--r--packet_io/packet_io_marsio.c115
-rw-r--r--packet_io/packet_io_status.cpp34
-rw-r--r--plugin/src/plugin.c35
-rw-r--r--plugin/src/plugin_protocol.c336
-rw-r--r--run/conf/main.conf8
18 files changed, 2000 insertions, 1918 deletions
diff --git a/.gitignore b/.gitignore
index b57d81f..1cb9ea2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,8 @@ run/log/
run/sapp
version.txt
cmake-build-debug
+.vscode/*
+.DS_Store
+GPATH
+GRTAGS
+GTAGS
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7fd0e70..d568f24 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,37 +11,52 @@ include(Version)
set(CMAKE_MACOSX_RPATH 0)
-set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Werror -DHIGH_PERF=0")
-set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Werror -DHIGH_PERF=0")
+set(CMAKE_BUILD_TYPE "DEBUG" CACHE STRING
+ " set CMAKE_BUILD_TYPE chosen by the user, using DEBUG as default")
+set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS DEBUG RELEASE
+ RELWITHDEBINFO MINSIZEREL)
+
+message(STATUS "CPU_PROFILE='${CPU_PROFILE}'")
+set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Werror -DHIGH_PERF=1")
+set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Werror -DHIGH_PERF=1")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG -DHIGH_PERF=0")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -DHIGH_PERF=0")
-#set(CMAKE_INSTALL_PREFIX /home/ceiec/sapp/)
set(CMAKE_INSTALL_PREFIX /home/mesasoft/sapp_run/)
-option(PLATFORM_MODE_SERIAL "Using serial mode" FALSE)
+set(PLATFORM_MODE "MIRROR" CACHE STRING
+ " set platform mode chosen by the user, using mirror as default")
+set_property(CACHE PLATFORM_MODE PROPERTY STRINGS MIRROR INLINE)
+message(STATUS "PLATFORM_MODE='${PLATFORM_MODE}'")
#static link option
-option(ENABLE_STATIC_LINK "Enable static link" TRUE)
+option(STATIC_LINK "Enable static link" TRUE)
# CPU profiler
-option(OPT_USE_PROFILER "Use gperf cpu profiler" OFF)
-if(OPT_USE_PROFILER)
+set(CPU_PROFILE "OFF" CACHE STRING
+ " set cpu profiler chosen by the user, using OFF as default")
+set_property(CACHE CPU_PROFILE PROPERTY STRINGS OFF GPERF GPROF)
+message(STATUS "CPU_PROFILE='${CPU_PROFILE}'")
+if(CPU_PROFILE MATCHES "GPERF")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lprofiler")
+elseif(CPU_PROFILE MATCHES "GPROF")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpg")
endif()
#ASAN option
-option(ENABLE_SANITIZE_ADDRESS "Enable AddressSanitizer" FALSE)
-option(ENABLE_SANITIZE_THREAD "Enable ThreadSanitizer" FALSE)
+set(ASAN_OPTION "OFF" CACHE STRING
+ " set asan type chosen by the user, using OFF as default")
+set_property(CACHE ASAN_OPTION PROPERTY STRINGS OFF ADDRESS THREAD)
+message(STATUS "ASAN_OPTION='${ASAN_OPTION}'")
-if(ENABLE_SANITIZE_ADDRESS)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -DCMAKE_BUILD_TYPE=Debug -fsanitize=address -fno-omit-frame-pointer")
+if(ASAN_OPTION MATCHES "ADDRESS")
+ set(CMAKE_C_FLAGS "${CMAKADDRESS} -g -DCMAKE_BUILD_TYPE=Debug -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DCMAKE_BUILD_TYPE=Debug -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
-elseif(ENABLE_SANITIZE_THREAD)
+elseif(ASAN_OPTION MATCHES "THREAD")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -DCMAKE_BUILD_TYPE=Debug -fsanitize=thread -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DCMAKE_BUILD_TYPE=Debug -fsanitize=thread -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
@@ -51,42 +66,15 @@ endif()
# MESA SDK Root
set(MESA_SDK_PREFIX "/opt/MESA/" CACHE STRING "MESA Framework Prefix")
+
# Capture Mode
-option(OPT_IOMODE_PCAP "Capture network traffic with libpcap" ON)
-option(OPT_IOMODE_PAG "Capture network traffic with libpag" OFF)
-#option(OPT_IOMODE_PPF "Capture network traffic with libppf" OFF)
-#option(OPT_IOMODE_PFRING "Capture network traffic with PF-RING" OFF)
-#option(OPT_IOMODE_DPDK "Capture network traffic with DPDK" OFF)
-#option(OPT_IOMODE_PAG_N95 "Capture network traffic with N95" OFF)
-option(OPT_IOMODE_MARSIO "Capture network traffic with MARSIO" OFF)
-
-if(OPT_IOMODE_PCAP)
- set(CAPTURE_MODE "PCAP")
-endif()
+set(CAPTURE_MODE "PCAP" CACHE STRING
+ "CAPTURE_MODE set Capture network traffic chosen by the user, using PCAP as default")
-if(OPT_IOMODE_PAG)
- set(CAPTURE_MODE "PAG")
-endif()
+set_property(CACHE CAPTURE_MODE PROPERTY STRINGS PCAP MARSIO PAG)
+
+message(STATUS "CAPTURE_MODE='${CAPTURE_MODE}'")
-#if(OPT_IOMODE_PPF)
-# set(CAPTURE_MODE "PPF")
-#endif()
-#
-#if(OPT_IOMODE_PFRING)
-# set(CAPTURE_MODE "PFRING")
-#endif()
-#
-#if(OPT_IOMODE_DPDK)
-# set(CAPTURE_MODE "DPDK")
-#endif()
-#
-#if(OPT_IOMODE_PAG_N95)
-# set(CAPTURE_MODE "PAG_N95")
-#endif()
-
-if(OPT_IOMODE_MARSIO)
- set(CAPTURE_MODE "MARSIO")
-endif()
if(CAPTURE_MODE MATCHES "PCAP")
set(CAPTURE_DEFINITIONS -DONLY_PCAP -DIOMODE_PCAP)
@@ -96,46 +84,34 @@ if(CAPTURE_MODE MATCHES "PAG")
set(CAPTURE_DEFINITIONS -DCAPTURE_MODE_PAG)
endif()
-#if(CAPTURE_MODE MATCHES "PPF")
-# set(CAPTURE_DEFINITIONS -DCAPTURE_MODE_PPF)
-#endif()
-#
-#if(CAPTURE_MODE MATCHES "PFRING")
-# set(CAPTURE_DEFINITIONS -DCAPTURE_MODE_PFRING)
-#endif()
-#
-#if(CAPTURE_MODE MATCHES "DPDK")
-# set(CAPTURE_DEFINITIONS -DCAPTURE_MODE_DPDK)
-#endif()
-
if(CAPTURE_MODE MATCHES "MARSIO")
set(CAPTURE_DEFINITIONS -DCAPTURE_MODE_MARSIO -DIOMODE_MARSIO)
endif()
+
# Memory Allocator
-option(OPT_USE_DICTATOR "Use Dictator2 memory allocator" OFF)
-option(OPT_USE_DICTATOR_DEBUG "Use Dictator2 memory allocator" OFF)
-option(OPT_USE_TCMALLOC "Use TCmalloc memory allocator" OFF)
-option(OPT_USE_TCMALLOC_MINI "Use TCmalloc memory allocator" OFF)
-option(OPT_USE_JEMALLOC "Use JEmalloc memory allocator" OFF)
+set(MEM_POOL "OFF" CACHE STRING
+ " set mem alloc chosen by the user, using off as default")
+set_property(CACHE MEM_POOL PROPERTY STRINGS OFF DICTATOR DICTATOR_DEBUG
+ TCMALLOC TCMALLOC_MINI JEMALLOC)
+message(STATUS "MEM_POOL='${MEM_POOL}'")
-if(OPT_USE_DICTATOR_DEBUG)
+if(MEM_POOL MATCHES "DICTATOR")
set(MEM_POOL_DEFINITIONS -DDICTATOR_DEBUG)
-endif()
-if(OPT_USE_DICTATOR OR OPT_USE_DICTATOR_DEBUG)
+elseif(MEM_POOL MATCHES "DICTATOR_DEBUG")
set(MEM_POOL_DEFINITIONS ${MEM_POOL_DEFINITIONS} -DUSE_MEM_POOL=1
-DUSE_MEMPOOL)
-elseif(OPT_USE_TCMALLOC_MINI)
+elseif(MEM_POOL MATCHES "TCMALLOC_MINI")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -ltcmalloc_minimal -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
-elseif(OPT_USE_TCMALLOC)
+elseif(MEM_POOL MATCHES "TCMALLOC")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -ltcmalloc -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
-elseif(OPT_USE_JEMALLOC)
+elseif(MEM_POOL MATCHES "JEMALLOC")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -ljemalloc -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
endif()
add_definitions(${CAPTURE_DEFINITIONS} ${MEM_POOL_DEFINITIONS} -D__FAVOR_BSD=1
- -D__USE_BSD=1 -D_GNU_SOURCE=1 -DMESA_SAPP_PLATFORM=1)
+ -D__USE_BS=1 -D_GNU_SOURCE=1 -DMESA_SAPP_PLATFORM=1)
set(SAPP_DEPEND_DYN_LIB MESA_handle_logger MESA_htable pthread MESA_field_stat2)
@@ -199,13 +175,13 @@ if(CAPTURE_MODE MATCHES "PAG")
install(FILES ${CMAKE_BINARY_DIR}/packet_io/packet_io_pag.so DESTINATION platform_lib)
endif()
-#if(CAPTURE_MODE MATCHES "PCAP")
+if(CAPTURE_MODE MATCHES "PCAP")
install(FILES ${CMAKE_BINARY_DIR}/packet_io/packet_io_pcap.so DESTINATION platform_lib)
-#endif()
+endif()
install(FILES run/plug/protocol/conflist_protocol.inf DESTINATION plug/protocol)
-if(NOT PLATFORM_MODE_SERIAL)
+if(PLATFORM_MODE MATCHES "MIRROR")
install(FILES run/plug/protocol/isakmp_protocol_plug/isakmp_protocol_plug.inf DESTINATION plug/protocol/isakmp_protocol_plug)
install(FILES ${CMAKE_BINARY_DIR}/inner_plug/isakmp_protocol_plug.so DESTINATION plug/protocol/isakmp_protocol_plug)
@@ -218,7 +194,7 @@ endif()
install(FILES run/plug/platform/conflist_platform.inf DESTINATION plug/platform)
-if(PLATFORM_MODE_SERIAL)
+if(PLATFORM_MODE MATCHES "INLINE")
install(FILES run/plug/platform/g_device_plug/g_device_plug.inf DESTINATION plug/platform/g_device_plug)
install(FILES ${CMAKE_BINARY_DIR}/inner_plug/g_device_plug.so DESTINATION plug/platform/g_device_plug)
endif()
@@ -231,4 +207,4 @@ install(FILES ${CMAKE_BINARY_DIR}/test_so/test_app_sapp.so DESTINATION plug/busi
install(FILES ${CMAKE_BINARY_DIR}/test_so/trace_delay.so DESTINATION plug/business/test_app)
-include(Package) \ No newline at end of file
+include(Package)
diff --git a/dealpkt/callapp.c b/dealpkt/callapp.c
index 0a6ce6f..a484a19 100644
--- a/dealpkt/callapp.c
+++ b/dealpkt/callapp.c
@@ -1,928 +1,936 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <assert.h>
-#include "project_requirement.h"
-#include "stream_internal.h"
-#include "stream_manage.h"
-#include "packet_io_internal.h"
-#include "project_internal.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-static int g_StreamTcpFunNum=0;
-static stFunArray g_StreamTcpFun[MAX_FUN_NUM];
-
-static int g_StreamTcpAllFunNum=0;
-static stFunArray g_StreamTcpAllFun[MAX_FUN_NUM];
-
-static char (*g_StreamTcpTakeover)(const struct streaminfo *pstream,void **pme, int thread_seq, const void *raw_pkt)=NULL;
-
-static int g_StreamUdpFunNum=0;
-static stFunArray g_StreamUdpFun[MAX_FUN_NUM];
-
-static int g_Ipv4FunNum=0;
-static stFunArray g_Ipv4Fun[MAX_FUN_NUM];
-
-static int g_Ipv6FunNum=0;
-static stFunArray g_Ipv6Fun[MAX_FUN_NUM];
-
-static int g_Ipv4FragFunNum=0;
-static stFunArray g_Ipv4FragFun[MAX_FUN_NUM];
-
-static int g_Ipv6FragFunNum=0;
-static stFunArray g_Ipv6FragFun[MAX_FUN_NUM];
-
-/* 2016-09-01 lijia add, phony plug entry, will not be called in fact. */
-static int g_PhonyFunNum=0;
-static stFunArray g_PhonyFun[MAX_FUN_NUM];
-
-int g_PollingFunNum=0;
-static stFunArray g_PollingFun[MAX_FUN_NUM];
-
-typedef struct _stStreamFunInfo
-{
- char appState;
- int funtype;/* 2014-12-31 lqy add */
- char (*pfun)(void);
- void *pAppInfo;
- struct _stStreamFunInfo *next;
-}StreamFunInfo;
-
-static inline int is_raw_cb(int cb_type);
-
-extern int G_TCP_FLOW_STAT_PROJECT_ID;
-
-#ifdef IIEFD_DUAL_STACK
-static int judge_pure_ipv4_stack(const struct streaminfo *pstream, const void *a_packet);
-/* iiefd�����е��ܻص�����, ֻ�д�IPv4�İ��Ŵ��� */
-extern "C" char calltcpApp_old(struct streaminfo *pstream,void **pme, int thread_seq,void *a_packet);
-extern "C" char callIpApp_old(struct streaminfo *pstream,int routedir, int thread_seq,void *a_packet);
-#endif
-
-void timestamp_record(enum timestamp_level level, const raw_pkt_t *raw_pkt, int thread_seq);
-
-/* 2014-12-31 lqy add */
-int stream_register_funtoArray(int funtype,char (*x)(void),stFunArray *pArrary,int *pNum)
-{
- if(*pNum>=MAX_FUN_NUM)
- {
- printf("too many funcitons ,max ip fun is %d\n",MAX_FUN_NUM);
- return -1;
- }
-
- pArrary[(*pNum)].funtype=funtype;
- pArrary[(*pNum)].pfun=x;
- (*pNum)++;
- return 0;
-}
-
-int stream_register_fun(int funtype,char (*x)(void))
-{
- int ret=0;
- switch(funtype)
- {
- case FUN_TYPE_IPV4:
- ret=stream_register_funtoArray(FUN_TYPE_IPV4,x,g_Ipv4Fun,&g_Ipv4FunNum);
- break;
- case FUN_TYPE_IPV4_FRAG:
- ret=stream_register_funtoArray(FUN_TYPE_IPV4_FRAG,x,g_Ipv4FragFun,&g_Ipv4FragFunNum);
- break;
- case FUN_TYPE_IPV6_FRAG:
- ret=stream_register_funtoArray(FUN_TYPE_IPV6_FRAG,x,g_Ipv6FragFun,&g_Ipv6FragFunNum);
- break;
- case FUN_TYPE_IPV6:
- ret=stream_register_funtoArray(FUN_TYPE_IPV6,x,g_Ipv6Fun,&g_Ipv6FunNum);
- break;
- case FUN_TYPE_TCP:
- ret=stream_register_funtoArray(FUN_TYPE_TCP,x,g_StreamTcpFun,&g_StreamTcpFunNum);;
- break;
- case FUN_TYPE_TCPALL:
- ret=stream_register_funtoArray(FUN_TYPE_TCPALL,x,g_StreamTcpAllFun,&g_StreamTcpAllFunNum);
- break;
- case FUN_TYPE_UDP:
- ret=stream_register_funtoArray(FUN_TYPE_UDP,x,g_StreamUdpFun,&g_StreamUdpFunNum);
- break;
- case FUN_TYPE_IPV4_RAW:
- ret=stream_register_funtoArray(FUN_TYPE_IPV4_RAW,x,g_Ipv4Fun,&g_Ipv4FunNum);
- break;
- case FUN_TYPE_IPV4_FRAG_RAW:
- ret=stream_register_funtoArray(FUN_TYPE_IPV4_FRAG_RAW,x,g_Ipv4FragFun,&g_Ipv4FragFunNum);
- break;
- case FUN_TYPE_IPV6_RAW:
- ret=stream_register_funtoArray(FUN_TYPE_IPV6_RAW,x,g_Ipv6Fun,&g_Ipv6FunNum);
- break;
- case FUN_TYPE_IPV6_FRAG_RAW:
- ret=stream_register_funtoArray(FUN_TYPE_IPV6_FRAG_RAW,x,g_Ipv6FragFun,&g_Ipv6FragFunNum);
- break;
- case FUN_TYPE_TCP_RAW:
- ret=stream_register_funtoArray(FUN_TYPE_TCP_RAW,x,g_StreamTcpFun,&g_StreamTcpFunNum);;
- break;
-
- case FUN_TYPE_TCPALL_RAW:
- ret=stream_register_funtoArray(FUN_TYPE_TCPALL_RAW,x,g_StreamTcpAllFun,&g_StreamTcpAllFunNum);
- break;
-
- case FUN_TYPE_UDP_RAW:
- ret=stream_register_funtoArray(FUN_TYPE_UDP_RAW,x,g_StreamUdpFun,&g_StreamUdpFunNum);
- break;
-
- case FUN_TYPE_PHONY:
- g_PhonyFunNum = 0;
- g_PhonyFun[0].pfun = NULL;
- ret = 0; /* phony entry, do nothing! */
- break;
-
- case FUN_TYPE_POLLING:
- ret=stream_register_funtoArray(FUN_TYPE_POLLING, x, g_PollingFun,&g_PollingFunNum);
- break;
-
- default:
- ret=-1;
- }
-
- return ret;
-}
-
-int stream_register_ip (IPv4_CB_FUN_T x)
-{
- return stream_register_funtoArray(FUN_TYPE_IPV4,(char (*)())x,g_Ipv4Fun,&g_Ipv4FunNum);
-}
-
-int stream_register_ip_frag (IPv4_CB_FUN_T x)
-{
- return stream_register_funtoArray(FUN_TYPE_IPV4_FRAG,(char (*)())x,g_Ipv4FragFun,&g_Ipv4FragFunNum);
-}
-
-int stream_register_ip_raw (SAPP_PKT_CB_FUN_T x)
-{
- return stream_register_funtoArray(FUN_TYPE_IPV4_RAW,(char (*)())x,g_Ipv4Fun,&g_Ipv4FunNum);
-}
-
-int stream_register_ipv4_frag_raw (SAPP_PKT_CB_FUN_T x)
-{
- return stream_register_funtoArray(FUN_TYPE_IPV4_FRAG_RAW,(char (*)())x,g_Ipv4FragFun,&g_Ipv4FragFunNum);
-}
-
-int stream_register_ipv6 (IPv6_CB_FUN_T x)
-{
- return stream_register_funtoArray(FUN_TYPE_IPV6,(char (*)())x,g_Ipv6Fun,&g_Ipv6FunNum);
-}
-
-int stream_register_ipv6_frag(IPv4_CB_FUN_T x)
-{
- return stream_register_funtoArray(FUN_TYPE_IPV6_FRAG,(char (*)())x,g_Ipv6FragFun,&g_Ipv6FragFunNum);
-}
-
-int stream_register_ipv6_raw (SAPP_PKT_CB_FUN_T x)
-{
- return stream_register_funtoArray(FUN_TYPE_IPV6_RAW,(char (*)())x,g_Ipv6Fun,&g_Ipv6FunNum);
-}
-
-int stream_register_ipv6_frag_raw (IPv4_CB_FUN_T x)
-{
- return stream_register_funtoArray(FUN_TYPE_IPV6_FRAG_RAW,(char (*)())x,g_Ipv6FragFun,&g_Ipv6FragFunNum);
-}
-
-int stream_register_tcp (STREAM_CB_FUN_T x)
-{
- return stream_register_funtoArray(FUN_TYPE_TCP,(char (*)())x,g_StreamTcpFun,&g_StreamTcpFunNum);
-}
-
-
-int stream_register_tcp_allpkt (STREAM_CB_FUN_T x)
-{
- return stream_register_funtoArray(FUN_TYPE_TCPALL,(char (*)())x,g_StreamTcpAllFun,&g_StreamTcpAllFunNum);
-
-}
-int stream_register_udp (STREAM_CB_FUN_T x)
-{
- return stream_register_funtoArray(FUN_TYPE_UDP,(char (*)())x,g_StreamUdpFun,&g_StreamUdpFunNum);
-}
-
-
-int stream_register_tcp_raw(SAPP_STREAM_FUN_T x)
-{
- return stream_register_funtoArray(FUN_TYPE_TCP_RAW,(char (*)())x,g_StreamTcpFun,&g_StreamTcpFunNum);
-}
-
-
-int stream_register_tcp_allpkt_raw(SAPP_STREAM_FUN_T x)
-{
- return stream_register_funtoArray(FUN_TYPE_TCPALL_RAW,(char (*)())x,g_StreamTcpAllFun,&g_StreamTcpAllFunNum);
-
-}
-int stream_register_udp_raw(SAPP_STREAM_FUN_T x)
-{
- return stream_register_funtoArray(FUN_TYPE_UDP_RAW,(char (*)())x,g_StreamUdpFun,&g_StreamUdpFunNum);
-}
-
-
-int stream_register_tcp_takeover (STREAM_CB_FUN_T x)
-{
- if(g_StreamTcpTakeover!=NULL)
- {
- printf("only support one take over fun \n");
- return -1;
- }
- g_StreamTcpTakeover=x;
- return 0;
-}
-
-/*
- lijia 2015-01-12 add this_iphdr,
- �����IP��Ƭ����İ�, ������ʽ�Ĵ���IP��ͷ, ����ֻ��raw_hdr, �޷���ȡ������IP��ͷ.
-*/
-#if 0
-int stream_process(struct streaminfo *a_stream,const void *this_iphdr, const void *raw_pkt,int funnum,stFunArray *pfunAarry,void **apme,unsigned char *opstate)
-#else
-int stream_process(struct streaminfo *a_stream,const void *this_iphdr, const void *transport_hdr, const void *raw_pkt,
- int funnum,stFunArray *pfunAarry,void **apme,unsigned char *opstate)
-#endif
-{
- int i=0;
- int ret=PASS;
- StreamFunInfo *pFunList=NULL;
- StreamFunInfo *pFunInfo=NULL;
- StreamFunInfo *pNext=NULL,*pPrev=NULL;
- UCHAR threadnum = a_stream->threadnum;
-
- if(funnum==0)
- {
- *opstate= OP_STATE_CLOSE;
- return ret;
- }
-
-#if 0
- /* 2014-12-31 lijia add, ��ȡ�²�IP��ַ, ���д�����, ��Ҫ���� */
- real_stream = skip_proxy_phony_stream(a_stream->pfather);
- if(raw_pkt){ /* ��ʱ��̭��ʱ, a_packetΪNULL */
- related_iphdr = get_this_layer_header(real_stream);
- }
-#endif
-
- if(*opstate == OP_STATE_PENDING )
- {
- pFunList = (StreamFunInfo*)( *apme);
-
- for(i=0;i<funnum;i++)
- {
- if(pFunInfo==NULL)
- {
- pFunInfo=(StreamFunInfo *)dictator_malloc(threadnum,sizeof(StreamFunInfo));
- }
- pFunInfo->appState=APP_STATE_GIVEME;
- pFunInfo->pAppInfo=NULL;
- pFunInfo->funtype=pfunAarry[i].funtype;
- pFunInfo->pfun=pfunAarry[i].pfun;
- pFunInfo->next=NULL;
- //add by lqy 20141230
- //ע�����µ�ֻ����stream_raw���͵ĺ������������ò�һ��
- //if(pFunInfo->funtype>FUN_TYPE_IPV6_RAW)
- if(is_raw_cb(pFunInfo->funtype)){
- pFunInfo->appState=((SAPP_STREAM_FUN_T)pFunInfo->pfun)(a_stream,transport_hdr,raw_pkt,&(pFunInfo->pAppInfo));
- }else{
-#if 0 // IIEFD_DUAL_STACK
- /* */
- if(judge_pure_ipv4_stack(a_stream, this_iphdr) == 1){
- /* ��IPv4����, ����sapp��� */
- if((void *)&calltcpApp_old == (void *)pFunInfo->pfun){
- pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),a_stream->threadnum, this_iphdr);
- }
- }else{
- if((void *)&calltcpApp_old != (void *)pFunInfo->pfun){
- pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),a_stream->threadnum, this_iphdr);
- }
- }
-#else
- pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),threadnum, this_iphdr);
-#endif
- }
- if(pFunInfo->appState&APP_STATE_DROPPKT)
- {
- ret=DROP;
- }
-// if(pFunInfo->appState==APP_STATE_GIVEME)
- if(!(pFunInfo->appState&APP_STATE_DROPME))
- {
-
- if(pFunList==NULL)
- {
- pFunList=pFunInfo;
- }
- else
- {
- pPrev->next=pFunInfo;
- }
- pPrev=pFunInfo;
- pFunInfo=NULL;
- }
-
- }
- //����Ҫ�ٴ��������fun���������ͷ�
- if(pFunInfo!=NULL)
- {
- dictator_free(threadnum,pFunInfo);
- pFunInfo = NULL;
- }
-
- //����Ҫ�ٴ��Ͱ��Ļص�����
- if(pFunList!=NULL)
- {
- *apme = pFunList;
- *opstate= OP_STATE_DATA;
- }
- else
- {
- *opstate= OP_STATE_CLOSE;
- }
- return ret;
-
- }
-
- pFunList = (StreamFunInfo *)*apme;
- //����Ѿ�û��Ҫ�����ĺ�����
- if(pFunList==NULL)
- {
- *opstate= OP_STATE_CLOSE;
- return ret;
- }
- if( *opstate==OP_STATE_DATA)
- {
- pFunInfo=pFunList;
- pPrev=NULL;
- while(pFunInfo)
- {
- //add by lqy 20141230
- //ע�����µ�ֻ����stream_raw���͵ĺ������������ò�һ��
- //if(pFunInfo->funtype>FUN_TYPE_IPV6_RAW)
- if(is_raw_cb(pFunInfo->funtype)){
- pFunInfo->appState=((SAPP_STREAM_FUN_T)pFunInfo->pfun)(a_stream,transport_hdr,raw_pkt,&(pFunInfo->pAppInfo));
- }else{
-#if 0 //IIEFD_DUAL_STACK
- /* */
- if(judge_pure_ipv4_stack(a_stream, this_iphdr) == 1){
- /* ��IPv4����, ����sapp��� */
- if((void *)&calltcpApp_old == (void *)pFunInfo->pfun){
- pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),a_stream->threadnum, this_iphdr);
- }
- }else{
- if((void *)&calltcpApp_old != (void *)pFunInfo->pfun){
- pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),a_stream->threadnum, this_iphdr);
- }
- }
-#else
- pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),threadnum,this_iphdr);
-#endif
- }
- if(pFunInfo->appState&APP_STATE_DROPPKT)
- {
- ret=DROP;
- }
-
- if(pFunInfo->appState&APP_STATE_DROPME)
- {
- if(pPrev==NULL)
- {
- pFunList=pFunInfo->next;
- *apme= pFunList;
- }
- else
- {
- pPrev->next=pFunInfo->next;
- }
- pNext=pFunInfo->next;
-
- dictator_free(threadnum,pFunInfo);
- pFunInfo=pNext;
- }
- else
- {
- pPrev=pFunInfo;
- pFunInfo=pFunInfo->next;
- }
-
- }
- //���������д�Ҷ�����Ҫ��
- if(pFunList==NULL)
- {
- *opstate = OP_STATE_CLOSE;
- }
- }
- //���ӹر�,���״̬
- else if(*opstate == OP_STATE_CLOSE)
- {
- pFunInfo=pFunList;
- while(pFunInfo)
- {
- //add by lqy 20141230
- //ע�����µ�ֻ����stream_raw���͵ĺ������������ò�һ��
- //if(pFunInfo->funtype>FUN_TYPE_IPV6_RAW)
- if(is_raw_cb(pFunInfo->funtype)){
- ((SAPP_STREAM_FUN_T)pFunInfo->pfun)(a_stream,transport_hdr,raw_pkt,&(pFunInfo->pAppInfo));
- }else{
-#if 0 //IIEFD_DUAL_STACK
- /* */
- if(judge_pure_ipv4_stack(a_stream, this_iphdr) == 1){
- /* ��IPv4����, ����sapp��� */
- if((void *)&calltcpApp_old == (void *)pFunInfo->pfun){
- pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),a_stream->threadnum, this_iphdr);
- }
- }else{
- if((void *)&calltcpApp_old != (void *)pFunInfo->pfun){
- pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),a_stream->threadnum, this_iphdr);
- }
- }
-#else
- ((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),threadnum,this_iphdr);
-#endif
- }
- pNext=pFunInfo->next;
- dictator_free(threadnum,pFunInfo);
-
- pFunInfo=pNext;
- }
- *apme=NULL;
- }
-
- return ret;
-}
-
-int stream_process_udp_single(struct streaminfo *a_udp,const void * a_packet,void **apme,unsigned char *popstate)
-{
-
- int i=0;
- int ret=PASS;
- char appState=APP_STATE_GIVEME;
- void *pAppInfo=NULL;
- int funtype=0;
-
- for(i=0;i<g_StreamUdpFunNum;i++)
- {
- funtype=g_StreamUdpFun[i].funtype;
- //add by lqy 20141230
- //ע�����µ�ֻ����stream_raw���͵ĺ������������ò�һ��
- //if(funtype>FUN_TYPE_IPV6_RAW)
- if(is_raw_cb(funtype)){
- appState=g_StreamUdpFun[i].sapp_stream_fun(a_udp,a_packet,a_packet,&(pAppInfo));
- }else{
- appState=g_StreamUdpFun[i].stream_fun(a_udp,&(pAppInfo),a_udp->threadnum,a_packet);
- }
- if(appState&APP_STATE_DROPPKT)
- {
- ret=DROP;
- break;
- }
- }
- return ret;
-}
-
-#if 0
-/* 2015-12-24 lijia add, ����tcpdetail���ݼ��� */
-static inline void stream_update_tcp_data_count(struct streaminfo *a_tcp)
-{
- struct tcpdetail *ptcpdetail = a_tcp->ptcpdetail;
-
- if(NULL == ptcpdetail->pdata){
- return;
- }
-
- if(DIR_C2S == a_tcp->curdir){
- ptcpdetail->server_data_pkt_num++;
- ptcpdetail->server_data_bytes += ptcpdetail->datalen;
- }else{
- ptcpdetail->client_data_pkt_num++;
- ptcpdetail->client_data_bytes += ptcpdetail->datalen;
- }
-}
-#endif
-
-/*
- lijia 2015-01-12 modify, add this_iphdr,
- �����IP��Ƭ����İ�, ������ʽ�Ĵ���IP��ͷ, ����ֻ��raw_hdr, �޷���ȡ������IP��ͷ.
-*/
-#if 0
-int stream_process_tcp(struct streaminfo *a_tcp, const raw_pkt_t * a_packet,void **apme,unsigned char *popstate)
-#else
-int stream_process_tcp(struct streaminfo *a_tcp, const void *this_iphdr, const void *transport_hdr,
- const raw_pkt_t * raw_pkt,void **apme,unsigned char *popstate)
-#endif
-{
- int ret;
-
-#if 0 /* ����������������ʱ, ��ʱ�ر� */
- if(PKT_TYPE_NORMAL == a_tcp->addr.pkttype){
- timestamp_record(TS_LEVEL_BEFORE_PLUG, raw_pkt, a_tcp->threadnum);
- }
-#endif
-
- //stream_update_tcp_data_count(a_tcp);
- /* 2016-07-14 lijia add */
- if((G_TCP_FLOW_STAT_PROJECT_ID != -1)
- && (a_tcp->ptcpdetail->datalen > 0)
- && (STREAM_TYPE_TCP == a_tcp->type)){ /* ��ʹG_TCP_FLOW_STAT_PROJECT_ID����, a_tcp�����Ǵ�����, ��һ����TCP, �˴�Ҫ�ж������� */
- struct tcpdetail_private *pdetail_pr = (struct tcpdetail_private *)a_tcp->pdetail;
- if(DIR_C2S == a_tcp->curdir){
- pdetail_pr->flow_stat->C2S_data_pkt ++;
- pdetail_pr->flow_stat->C2S_data_byte += a_tcp->ptcpdetail->datalen;
- }else{
- pdetail_pr->flow_stat->S2C_data_pkt ++;
- pdetail_pr->flow_stat->S2C_data_byte += a_tcp->ptcpdetail->datalen;
- }
- }
-
-#if (0 == HIGH_PERF)
- if(a_tcp->addr.pkttype != PKT_TYPE_TCPREORDER){
- raw_ip_frag_list_stream_attach(a_tcp);
- }
-#endif
- ret = stream_process(a_tcp, this_iphdr, transport_hdr, raw_pkt,g_StreamTcpFunNum, g_StreamTcpFun,apme,popstate);
-
-#if (0 == HIGH_PERF)
- if(a_tcp->addr.pkttype != PKT_TYPE_TCPREORDER){
- raw_ip_frag_list_stream_detach(a_tcp);
- }
-#endif
-
-#if 0 /* ����������������ʱ, ��ʱ�ر� */
- if(PKT_TYPE_NORMAL == a_tcp->addr.pkttype){
- timestamp_record(TS_LEVEL_AFTER_PLUG, raw_pkt, a_tcp->threadnum);
- }
-#endif
- return ret;
-}
-
-/*
- lijia 2015-01-12 modify, add this_iphdr,
- �����IP��Ƭ����İ�, ������ʽ�Ĵ���IP��ͷ, ����ֻ��raw_hdr, �޷���ȡ������IP��ͷ.
-*/
-#if 0
-int stream_process_udp(struct streaminfo *a_udp,const raw_pkt_t * a_packet,void **apme,unsigned char *popstate)
-#else
-int stream_process_udp(struct streaminfo *a_udp, const void *this_iphdr, const void *transport_hdr,
- const raw_pkt_t * raw_pkt,void **apme,unsigned char *popstate)
-#endif
-{
- int ret;
-
-#if 0 /* ����������������ʱ, ��ʱ�ر� */
- if(PKT_TYPE_NORMAL == a_udp->addr.pkttype){
- timestamp_record(TS_LEVEL_BEFORE_PLUG, raw_pkt, a_udp->threadnum);
- }
-#endif
-
-#if (0 == HIGH_PERF)
- raw_ip_frag_list_stream_attach(a_udp);
-#endif
-
- ret = stream_process(a_udp, this_iphdr, transport_hdr,raw_pkt,g_StreamUdpFunNum, g_StreamUdpFun,apme,popstate);
-
-#if (0 == HIGH_PERF)
- raw_ip_frag_list_stream_detach(a_udp);
-#endif
-
-#if 0 /* ����������������ʱ, ��ʱ�ر� */
- if(PKT_TYPE_NORMAL == a_udp->addr.pkttype){
- timestamp_record(TS_LEVEL_AFTER_PLUG, raw_pkt, a_udp->threadnum);
- }
-#endif
- return ret;
-}
-
-/*
- lijia 2015-01-12 modify, add this_iphdr,
- �����IP��Ƭ����İ�, ������ʽ�Ĵ���IP��ͷ, ����ֻ��raw_hdr, �޷���ȡ������IP��ͷ.
-*/
-#if 0
-int stream_process_tcp_allpkt(struct streaminfo *a_tcp,const raw_pkt_t *a_packet,void **apme,unsigned char *popstate)
-#else
-int stream_process_tcp_allpkt(struct streaminfo *a_tcp,const void *this_iphdr, const void *transport_hdr,
- const raw_pkt_t *raw_pkt, void **apme,unsigned char *popstate)
-#endif
-{
- int ret;
-
-#if (0 == HIGH_PERF)
- raw_ip_frag_list_stream_attach(a_tcp);
-#endif
-
- ret = stream_process(a_tcp, this_iphdr, transport_hdr, raw_pkt,g_StreamTcpAllFunNum, g_StreamTcpAllFun,apme,popstate);
-
-#if (0 == HIGH_PERF)
- raw_ip_frag_list_stream_detach(a_tcp);
-#endif
-
- return ret;
-}
-
-#if 0 /* 20160928 lijia modify, iphdr */
-int stream_process_tcp_takeover(struct streaminfo *a_tcp, const void * raw_pkt)
-{
- return g_StreamTcpTakeover(a_tcp,NULL,a_tcp->threadnum, raw_pkt);
-}
-#else
-int stream_process_tcp_takeover(struct streaminfo *a_tcp, const void * iphdr)
-{
- return g_StreamTcpTakeover(a_tcp,NULL,a_tcp->threadnum, iphdr);
-}
-#endif
-
-
-int stream_process_ipv4(struct streaminfo *pfstream, const struct ip* this_layer_hdr,
- int thread_num,unsigned char routedir, const raw_pkt_t *raw_pkt)
-{
- int i;
- //int ret;
- int appret;
-
- for(i=0;i<g_Ipv4FunNum;i++)
- {
- if(g_Ipv4Fun[i].funtype==FUN_TYPE_IPV4)
- {
-#if 0 //IIEFD_DUAL_STACK
- /* */
- if(judge_pure_ipv4_stack(pfstream, this_layer_hdr) == 1){
- /* ��IPv4����, ����sapp��� */
- if((void *)&callIpApp_old != (void *)g_Ipv4Fun[i].stream_ipv4_fun){
- continue;
- }
- }else{
- /* �Ǵ�IPv4����, ����iiefd��� */
- if((void *)&callIpApp_old == (void *)g_Ipv4Fun[i].stream_ipv4_fun){
- continue;
- }
- }
-#else
- appret=g_Ipv4Fun[i].stream_ipv4_fun(pfstream,routedir,thread_num,this_layer_hdr);
-#endif
- }
- else
- {
- appret=g_Ipv4Fun[i].sapp_pkt_fun(pfstream,this_layer_hdr,raw_pkt);
- }
-
- if(unlikely(appret&APP_STATE_DROPPKT))
- {
- return DROP;
- }
- }
-
- return PASS;
-}
-
-
-int stream_process_ipv6(struct streaminfo *pfstream,const struct ip6_hdr *this_layer_hdr,
- int thread_num,unsigned char routedir, const raw_pkt_t *raw_pkt)
-{
- int i=0;
- int ret=PASS;
- int appret=APP_STATE_GIVEME;
-
- for(i=0;i<g_Ipv6FunNum;i++)
- {
- if(g_Ipv6Fun[i].funtype==FUN_TYPE_IPV6)
- {
- appret=g_Ipv6Fun[i].stream_ipv6_fun(pfstream,routedir,thread_num,this_layer_hdr);
- }
- else
- {
- appret=g_Ipv6Fun[i].sapp_pkt_fun(pfstream,this_layer_hdr,raw_pkt);
- }
- if(appret&APP_STATE_DROPPKT)
- {
- ret=DROP;
- return ret;
- }
- }
- return ret;
-}
-
-int stream_process_ipv4_frag(struct streaminfo *pstream, const struct ip* this_layer_hdr,
- int thread_num,unsigned char routedir, const raw_pkt_t *raw_pkt)
-{
- int i=0;
- int ret=PASS;
- int appret=APP_STATE_GIVEME;
-
- for(i=0;i<g_Ipv4FragFunNum;i++)
- {
- if(g_Ipv4FragFun[i].funtype==FUN_TYPE_IPV4_FRAG)
- {
- appret=g_Ipv4FragFun[i].stream_ipv4_fun(pstream,routedir,thread_num,this_layer_hdr);
- }
- else
- {
- appret=g_Ipv4FragFun[i].sapp_pkt_fun(pstream,this_layer_hdr,raw_pkt);
- }
-
- if(appret&APP_STATE_DROPPKT)
- {
- ret=DROP;
- return ret;
- }
- }
- return ret;
-}
-
-int stream_process_ipv6_frag(struct streaminfo *pstream,const struct ip6_hdr *this_layer_hdr,
- int thread_num,unsigned char routedir, const raw_pkt_t *raw_pkt)
-{
- int i=0;
- int ret=PASS;
- int appret=APP_STATE_GIVEME;
-
- for(i=0;i<g_Ipv6FragFunNum;i++)
- {
- if(g_Ipv6FragFun[i].funtype==FUN_TYPE_IPV6_FRAG)
- {
- appret=g_Ipv6FragFun[i].stream_ipv6_fun(pstream,routedir,thread_num,this_layer_hdr);
- }
- else
- {
- appret=g_Ipv6FragFun[i].sapp_pkt_fun(pstream,this_layer_hdr,raw_pkt);
- }
- if(appret&APP_STATE_DROPPKT)
- {
- ret=DROP;
- return ret;
- }
- }
- return ret;
-}
-
-/*
- 2016-09-26 lijia add,
- û�а�ʱ, ���������,
- ����������, �ײ��ղ�����ʱ, Ҳ����ò��, ʹ����ܼ�ʱ���CPU, ��һЩ�ǰ������Ĵ����߼�.
-*/
-int stream_process_polling(int thread_seq)
-{
- int i;
-
- for(i = 0; i < g_PollingFunNum; i++){
- g_PollingFun[i].stream_fun(NULL, NULL, thread_seq, NULL);
- }
-
- return 0;
-}
-
-extern int g_use_MESA_sleep_sw;
-extern void MESA_sleep(void);
-/*
- 2016-09-26 lijia add,
- �ײ�����û�а�ʱ, ����ô˺���, ����ƽ̨�����Ƿ������ȴ�, ���ǵ����ϲ���ѯ���.
-*/
-void idle_polling_call(int thread_seq)
-{
- if(0 == g_PollingFunNum){
- return;
- }else{
- stream_process_polling(thread_seq);
- }
-
- return;
-}
-
-#if 0 /* ���ò��ʵ�� */
-static inline int is_raw_cb(int cb_type)
-{
- int ret;
-
- switch(cb_type){
- case FUN_TYPE_IPV4:
- case FUN_TYPE_IPV4_FRAG:
- case FUN_TYPE_IPV6:
- case FUN_TYPE_IPV6_FRAG:
- case FUN_TYPE_TCP:
- case FUN_TYPE_TCPALL:
- case FUN_TYPE_UDP:
- ret = 0;
- break;
-
- case FUN_TYPE_IPV4_RAW:
- case FUN_TYPE_IPV4_FRAG_RAW:
- case FUN_TYPE_IPV6_RAW:
- case FUN_TYPE_IPV6_FRAG_RAW:
- case FUN_TYPE_TCP_RAW:
- case FUN_TYPE_TCPALL_RAW:
- case FUN_TYPE_UDP_RAW:
- ret = 1;
- break;
-
- default:
- assert(0);
- }
-
- return ret;
-}
-#else
-typedef struct
-{
- enum fun_type_t funtype;
- int is_raw;
-}raw_cb_fun_identify_t;
-
-const static raw_cb_fun_identify_t g_raw_cb_fun_identify_array[__FUN_TYPE_MAX] =
-{
- {FUN_TYPE_IPV4, 0},
- {FUN_TYPE_IPV6, 0},
- {FUN_TYPE_TCP, 0},
- {FUN_TYPE_TCPALL, 0},
- {FUN_TYPE_UDP, 0},
- {FUN_TYPE_IPV4_RAW, 1},
- {FUN_TYPE_IPV6_RAW, 1},
- {FUN_TYPE_TCP_RAW, 1},
- {FUN_TYPE_TCPALL_RAW, 1},
- {FUN_TYPE_UDP_RAW, 1},
- {FUN_TYPE_IPV4_FRAG, 0},
- {FUN_TYPE_IPV4_FRAG_RAW, 1},
- {FUN_TYPE_IPV6_FRAG, 0},
- {FUN_TYPE_IPV6_FRAG_RAW, 1},
-
-};
-
-static inline int is_raw_cb(int cb_type)
-{
- assert(cb_type < __FUN_TYPE_MAX);
- return g_raw_cb_fun_identify_array[cb_type].is_raw;
-}
-#endif
-
-
-
-#ifdef IIEFD_DUAL_STACK
-/* 2015-09-02 lijia add, for iieqd_dual_stack */
-static int judge_pure_ipv4_stack(const struct streaminfo *pstream, const void *a_packet)
-{
- int ret = 0;
- const mesa_ip4_hdr *ip4_hdr = (const mesa_ip4_hdr *)a_packet;
-
- switch(pstream->addr.addrtype){
- case __ADDR_TYPE_IP_PAIR_V4:
- if((IPPROTO_TCP != ip4_hdr->ip_p) && (IPPROTO_UDP != ip4_hdr->ip_p)){
- ret = 0;
- break;
- }
- if((NULL == pstream->pfather)
- ||((NULL != pstream->pfather) && (ADDR_TYPE_MAC == pstream->pfather->addr.addrtype))){
- ret = 1;
- }else{
- ret = 0;
- }
- break;
-
- case ADDR_TYPE_IPV4:
- if(__ADDR_TYPE_IP_PAIR_V4 != pstream->pfather->addr.addrtype){
- ret = 0;
- break;
- }
-
- if((pstream->pfather->pfather != NULL) && (ADDR_TYPE_MAC != pstream->pfather->pfather->addr.addrtype)){
- ret = 0;
- break;
- }
-
- ret = 1;
- break;
-
- default:
- ret = 0;
- break;
- }
-
- return ret;
-}
-#endif
-
- int g_packet_io_ipv6_switch = 0;
- extern int g_discard_ack_sw;
- int app_function_rationality_check(void)
-{
- /* 2015-01-12 lijia add, for error message */
- if((0 == tcp_support_all) && (g_StreamTcpAllFunNum != 0)){
- printf("\033[33m[Warning]You have registered 'TCP_ALL' plugin, but 'TcpAllEnable' in main.conf is disable! \033[0m\n");
- sleep(1);
- }
-
- if((0 == g_packet_io_ipv6_switch) && (g_Ipv6FunNum != 0)){
- printf("\033[33m[Warning]You have registered 'IPV6' plugin, but 'IPv6_module_enable' in main.conf is disable! \033[0m\n");
- sleep(1);
- }
-
- if((0 != tcp_support_all) && (g_discard_ack_sw != 0)){
-#if HIGH_PERF
- printf("\033[33m[Warning]Config conflict! 'TcpAllEnable' and 'discard_ack' is all enable, but in high-perf mode, discard_ack is keep enable!\033[0m\n");
-#else
- printf("\033[33m[Warning]Config conflict! 'TcpAllEnable' and 'discard_ack' is all enable, TCPALL plug can't get ACK pkt.\033[0m\n");
-#endif
- sleep(1);
- }
-
- return 0;
-}
-
-#ifdef __cplusplus
-}
-#endif
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <assert.h>
+#include "project_requirement.h"
+#include "stream_internal.h"
+#include "stream_manage.h"
+#include "packet_io_internal.h"
+#include "project_internal.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static int g_StreamTcpFunNum=0;
+static stFunArray g_StreamTcpFun[MAX_FUN_NUM];
+
+static int g_StreamTcpAllFunNum=0;
+static stFunArray g_StreamTcpAllFun[MAX_FUN_NUM];
+
+static char (*g_StreamTcpTakeover)(const struct streaminfo *pstream,void **pme, int thread_seq, const void *raw_pkt)=NULL;
+
+static int g_StreamUdpFunNum=0;
+static stFunArray g_StreamUdpFun[MAX_FUN_NUM];
+
+static int g_Ipv4FunNum=0;
+static stFunArray g_Ipv4Fun[MAX_FUN_NUM];
+
+static int g_Ipv6FunNum=0;
+static stFunArray g_Ipv6Fun[MAX_FUN_NUM];
+
+static int g_Ipv4FragFunNum=0;
+static stFunArray g_Ipv4FragFun[MAX_FUN_NUM];
+
+static int g_Ipv6FragFunNum=0;
+static stFunArray g_Ipv6FragFun[MAX_FUN_NUM];
+
+/* 2016-09-01 lijia add, phony plug entry, will not be called in fact. */
+static int g_PhonyFunNum=0;
+static stFunArray g_PhonyFun[MAX_FUN_NUM];
+
+int g_PollingFunNum=0;
+static stFunArray g_PollingFun[MAX_FUN_NUM];
+
+typedef struct _stStreamFunInfo
+{
+ char appState;
+ int funtype;/* 2014-12-31 lqy add */
+ char (*pfun)(void);
+ void *pAppInfo;
+ struct _stStreamFunInfo *next;
+}StreamFunInfo;
+
+static inline int is_raw_cb(int cb_type);
+
+extern int G_TCP_FLOW_STAT_PROJECT_ID;
+
+#ifdef IIEFD_DUAL_STACK
+static int judge_pure_ipv4_stack(const struct streaminfo *pstream, const void *a_packet);
+/* iiefd�����е��ܻص�����, ֻ�д�IPv4�İ��Ŵ��� */
+extern "C" char calltcpApp_old(struct streaminfo *pstream,void **pme, int thread_seq,void *a_packet);
+extern "C" char callIpApp_old(struct streaminfo *pstream,int routedir, int thread_seq,void *a_packet);
+#endif
+
+void timestamp_record(enum timestamp_level level, const raw_pkt_t *raw_pkt, int thread_seq);
+
+/* 2014-12-31 lqy add */
+int stream_register_funtoArray(int funtype,char (*x)(void),stFunArray *pArrary,int *pNum)
+{
+ if(*pNum>=MAX_FUN_NUM)
+ {
+ printf("too many funcitons ,max ip fun is %d\n",MAX_FUN_NUM);
+ return -1;
+ }
+
+ pArrary[(*pNum)].funtype=funtype;
+ pArrary[(*pNum)].pfun=x;
+ (*pNum)++;
+ return 0;
+}
+
+int stream_register_fun(int funtype,char (*x)(void))
+{
+ int ret=0;
+ switch(funtype)
+ {
+ case FUN_TYPE_IPV4:
+ ret=stream_register_funtoArray(FUN_TYPE_IPV4,x,g_Ipv4Fun,&g_Ipv4FunNum);
+ break;
+ case FUN_TYPE_IPV4_FRAG:
+ ret=stream_register_funtoArray(FUN_TYPE_IPV4_FRAG,x,g_Ipv4FragFun,&g_Ipv4FragFunNum);
+ break;
+ case FUN_TYPE_IPV6_FRAG:
+ ret=stream_register_funtoArray(FUN_TYPE_IPV6_FRAG,x,g_Ipv6FragFun,&g_Ipv6FragFunNum);
+ break;
+ case FUN_TYPE_IPV6:
+ ret=stream_register_funtoArray(FUN_TYPE_IPV6,x,g_Ipv6Fun,&g_Ipv6FunNum);
+ break;
+ case FUN_TYPE_TCP:
+ ret=stream_register_funtoArray(FUN_TYPE_TCP,x,g_StreamTcpFun,&g_StreamTcpFunNum);;
+ break;
+ case FUN_TYPE_TCPALL:
+ ret=stream_register_funtoArray(FUN_TYPE_TCPALL,x,g_StreamTcpAllFun,&g_StreamTcpAllFunNum);
+ break;
+ case FUN_TYPE_UDP:
+ ret=stream_register_funtoArray(FUN_TYPE_UDP,x,g_StreamUdpFun,&g_StreamUdpFunNum);
+ break;
+ case FUN_TYPE_IPV4_RAW:
+ ret=stream_register_funtoArray(FUN_TYPE_IPV4_RAW,x,g_Ipv4Fun,&g_Ipv4FunNum);
+ break;
+ case FUN_TYPE_IPV4_FRAG_RAW:
+ ret=stream_register_funtoArray(FUN_TYPE_IPV4_FRAG_RAW,x,g_Ipv4FragFun,&g_Ipv4FragFunNum);
+ break;
+ case FUN_TYPE_IPV6_RAW:
+ ret=stream_register_funtoArray(FUN_TYPE_IPV6_RAW,x,g_Ipv6Fun,&g_Ipv6FunNum);
+ break;
+ case FUN_TYPE_IPV6_FRAG_RAW:
+ ret=stream_register_funtoArray(FUN_TYPE_IPV6_FRAG_RAW,x,g_Ipv6FragFun,&g_Ipv6FragFunNum);
+ break;
+ case FUN_TYPE_TCP_RAW:
+ ret=stream_register_funtoArray(FUN_TYPE_TCP_RAW,x,g_StreamTcpFun,&g_StreamTcpFunNum);;
+ break;
+
+ case FUN_TYPE_TCPALL_RAW:
+ ret=stream_register_funtoArray(FUN_TYPE_TCPALL_RAW,x,g_StreamTcpAllFun,&g_StreamTcpAllFunNum);
+ break;
+
+ case FUN_TYPE_UDP_RAW:
+ ret=stream_register_funtoArray(FUN_TYPE_UDP_RAW,x,g_StreamUdpFun,&g_StreamUdpFunNum);
+ break;
+
+ case FUN_TYPE_PHONY:
+ g_PhonyFunNum = 0;
+ g_PhonyFun[0].pfun = NULL;
+ ret = 0; /* phony entry, do nothing! */
+ break;
+
+ case FUN_TYPE_POLLING:
+ ret=stream_register_funtoArray(FUN_TYPE_POLLING, x, g_PollingFun,&g_PollingFunNum);
+ break;
+
+ default:
+ ret=-1;
+ }
+
+ return ret;
+}
+
+int stream_register_ip (IPv4_CB_FUN_T x)
+{
+ return stream_register_funtoArray(FUN_TYPE_IPV4,(char (*)())x,g_Ipv4Fun,&g_Ipv4FunNum);
+}
+
+int stream_register_ip_frag (IPv4_CB_FUN_T x)
+{
+ return stream_register_funtoArray(FUN_TYPE_IPV4_FRAG,(char (*)())x,g_Ipv4FragFun,&g_Ipv4FragFunNum);
+}
+
+int stream_register_ip_raw (SAPP_PKT_CB_FUN_T x)
+{
+ return stream_register_funtoArray(FUN_TYPE_IPV4_RAW,(char (*)())x,g_Ipv4Fun,&g_Ipv4FunNum);
+}
+
+int stream_register_ipv4_frag_raw (SAPP_PKT_CB_FUN_T x)
+{
+ return stream_register_funtoArray(FUN_TYPE_IPV4_FRAG_RAW,(char (*)())x,g_Ipv4FragFun,&g_Ipv4FragFunNum);
+}
+
+int stream_register_ipv6 (IPv6_CB_FUN_T x)
+{
+ return stream_register_funtoArray(FUN_TYPE_IPV6,(char (*)())x,g_Ipv6Fun,&g_Ipv6FunNum);
+}
+
+int stream_register_ipv6_frag(IPv4_CB_FUN_T x)
+{
+ return stream_register_funtoArray(FUN_TYPE_IPV6_FRAG,(char (*)())x,g_Ipv6FragFun,&g_Ipv6FragFunNum);
+}
+
+int stream_register_ipv6_raw (SAPP_PKT_CB_FUN_T x)
+{
+ return stream_register_funtoArray(FUN_TYPE_IPV6_RAW,(char (*)())x,g_Ipv6Fun,&g_Ipv6FunNum);
+}
+
+int stream_register_ipv6_frag_raw (IPv4_CB_FUN_T x)
+{
+ return stream_register_funtoArray(FUN_TYPE_IPV6_FRAG_RAW,(char (*)())x,g_Ipv6FragFun,&g_Ipv6FragFunNum);
+}
+
+int stream_register_tcp (STREAM_CB_FUN_T x)
+{
+ return stream_register_funtoArray(FUN_TYPE_TCP,(char (*)())x,g_StreamTcpFun,&g_StreamTcpFunNum);
+}
+
+
+int stream_register_tcp_allpkt (STREAM_CB_FUN_T x)
+{
+ return stream_register_funtoArray(FUN_TYPE_TCPALL,(char (*)())x,g_StreamTcpAllFun,&g_StreamTcpAllFunNum);
+
+}
+int stream_register_udp (STREAM_CB_FUN_T x)
+{
+ return stream_register_funtoArray(FUN_TYPE_UDP,(char (*)())x,g_StreamUdpFun,&g_StreamUdpFunNum);
+}
+
+
+int stream_register_tcp_raw(SAPP_STREAM_FUN_T x)
+{
+ return stream_register_funtoArray(FUN_TYPE_TCP_RAW,(char (*)())x,g_StreamTcpFun,&g_StreamTcpFunNum);
+}
+
+
+int stream_register_tcp_allpkt_raw(SAPP_STREAM_FUN_T x)
+{
+ return stream_register_funtoArray(FUN_TYPE_TCPALL_RAW,(char (*)())x,g_StreamTcpAllFun,&g_StreamTcpAllFunNum);
+
+}
+int stream_register_udp_raw(SAPP_STREAM_FUN_T x)
+{
+ return stream_register_funtoArray(FUN_TYPE_UDP_RAW,(char (*)())x,g_StreamUdpFun,&g_StreamUdpFunNum);
+}
+
+
+int stream_register_tcp_takeover (STREAM_CB_FUN_T x)
+{
+ if(g_StreamTcpTakeover!=NULL)
+ {
+ printf("only support one take over fun \n");
+ return -1;
+ }
+ g_StreamTcpTakeover=x;
+ return 0;
+}
+
+/*
+ lijia 2015-01-12 add this_iphdr,
+ �����IP��Ƭ����İ�, ������ʽ�Ĵ���IP��ͷ, ����ֻ��raw_hdr, �޷���ȡ������IP��ͷ.
+*/
+#if 0
+int stream_process(struct streaminfo *a_stream,const void *this_iphdr, const void *raw_pkt,int funnum,stFunArray *pfunAarry,void **apme,unsigned char *opstate)
+#else
+int stream_process(struct streaminfo *a_stream,const void *this_iphdr, const void *transport_hdr, const void *raw_pkt,
+ int funnum,stFunArray *pfunAarry,void **apme,unsigned char *opstate)
+#endif
+{
+ int i=0;
+ int ret=PASS;
+ StreamFunInfo *pFunList=NULL;
+ StreamFunInfo *pFunInfo=NULL;
+ StreamFunInfo *pNext=NULL,*pPrev=NULL;
+ UCHAR threadnum = a_stream->threadnum;
+
+ if(funnum==0)
+ {
+ *opstate= OP_STATE_CLOSE;
+ return ret;
+ }
+
+#if 0
+ /* 2014-12-31 lijia add, ��ȡ�²�IP��ַ, ���д�����, ��Ҫ���� */
+ real_stream = skip_proxy_phony_stream(a_stream->pfather);
+ if(raw_pkt){ /* ��ʱ��̭��ʱ, a_packetΪNULL */
+ related_iphdr = get_this_layer_header(real_stream);
+ }
+#endif
+
+ if(*opstate == OP_STATE_PENDING )
+ {
+ pFunList = (StreamFunInfo*)( *apme);
+
+ for(i=0;i<funnum;i++)
+ {
+ if(pFunInfo==NULL)
+ {
+ pFunInfo=(StreamFunInfo *)dictator_malloc(threadnum,sizeof(StreamFunInfo));
+ }
+ pFunInfo->appState=APP_STATE_GIVEME;
+ pFunInfo->pAppInfo=NULL;
+ pFunInfo->funtype=pfunAarry[i].funtype;
+ pFunInfo->pfun=pfunAarry[i].pfun;
+ pFunInfo->next=NULL;
+ //add by lqy 20141230
+ //ע�����µ�ֻ����stream_raw���͵ĺ������������ò�һ��
+ //if(pFunInfo->funtype>FUN_TYPE_IPV6_RAW)
+ if(is_raw_cb(pFunInfo->funtype)){
+ pFunInfo->appState=((SAPP_STREAM_FUN_T)pFunInfo->pfun)(a_stream,transport_hdr,raw_pkt,&(pFunInfo->pAppInfo));
+ }else{
+#if 0 // IIEFD_DUAL_STACK
+ /* */
+ if(judge_pure_ipv4_stack(a_stream, this_iphdr) == 1){
+ /* ��IPv4����, ����sapp��� */
+ if((void *)&calltcpApp_old == (void *)pFunInfo->pfun){
+ pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),a_stream->threadnum, this_iphdr);
+ }
+ }else{
+ if((void *)&calltcpApp_old != (void *)pFunInfo->pfun){
+ pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),a_stream->threadnum, this_iphdr);
+ }
+ }
+#else
+ pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),threadnum, this_iphdr);
+#endif
+ }
+ if(pFunInfo->appState&APP_STATE_DROPPKT)
+ {
+ ret=DROP;
+ }
+// if(pFunInfo->appState==APP_STATE_GIVEME)
+ if(!(pFunInfo->appState&APP_STATE_DROPME))
+ {
+
+ if(pFunList==NULL)
+ {
+ pFunList=pFunInfo;
+ }
+ else
+ {
+ pPrev->next=pFunInfo;
+ }
+ pPrev=pFunInfo;
+ pFunInfo=NULL;
+ }
+
+ }
+ //����Ҫ�ٴ��������fun���������ͷ�
+ if(pFunInfo!=NULL)
+ {
+ dictator_free(threadnum,pFunInfo);
+ pFunInfo = NULL;
+ }
+
+ //����Ҫ�ٴ��Ͱ��Ļص�����
+ if(pFunList!=NULL)
+ {
+ *apme = pFunList;
+ *opstate= OP_STATE_DATA;
+ }
+ else
+ {
+ *opstate= OP_STATE_CLOSE;
+ if(a_stream->type == STREAM_TYPE_TCP)
+ {
+ g_SysInputInfo[threadnum][TCP_LINK_DISPOSABLE]++;
+ }
+ if(a_stream->type == STREAM_TYPE_UDP)
+ {
+ g_SysInputInfo[threadnum][UDP_LINK_DISPOSABLE]++;
+ }
+ }
+ return ret;
+
+ }
+
+ pFunList = (StreamFunInfo *)*apme;
+ //����Ѿ�û��Ҫ�����ĺ�����
+ if(pFunList==NULL)
+ {
+ *opstate= OP_STATE_CLOSE;
+ return ret;
+ }
+ if( *opstate==OP_STATE_DATA)
+ {
+ pFunInfo=pFunList;
+ pPrev=NULL;
+ while(pFunInfo)
+ {
+ //add by lqy 20141230
+ //ע�����µ�ֻ����stream_raw���͵ĺ������������ò�һ��
+ //if(pFunInfo->funtype>FUN_TYPE_IPV6_RAW)
+ if(is_raw_cb(pFunInfo->funtype)){
+ pFunInfo->appState=((SAPP_STREAM_FUN_T)pFunInfo->pfun)(a_stream,transport_hdr,raw_pkt,&(pFunInfo->pAppInfo));
+ }else{
+#if 0 //IIEFD_DUAL_STACK
+ /* */
+ if(judge_pure_ipv4_stack(a_stream, this_iphdr) == 1){
+ /* ��IPv4����, ����sapp��� */
+ if((void *)&calltcpApp_old == (void *)pFunInfo->pfun){
+ pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),a_stream->threadnum, this_iphdr);
+ }
+ }else{
+ if((void *)&calltcpApp_old != (void *)pFunInfo->pfun){
+ pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),a_stream->threadnum, this_iphdr);
+ }
+ }
+#else
+ pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),threadnum,this_iphdr);
+#endif
+ }
+ if(pFunInfo->appState&APP_STATE_DROPPKT)
+ {
+ ret=DROP;
+ }
+
+ if(pFunInfo->appState&APP_STATE_DROPME)
+ {
+ if(pPrev==NULL)
+ {
+ pFunList=pFunInfo->next;
+ *apme= pFunList;
+ }
+ else
+ {
+ pPrev->next=pFunInfo->next;
+ }
+ pNext=pFunInfo->next;
+
+ dictator_free(threadnum,pFunInfo);
+ pFunInfo=pNext;
+ }
+ else
+ {
+ pPrev=pFunInfo;
+ pFunInfo=pFunInfo->next;
+ }
+
+ }
+ //���������д�Ҷ�����Ҫ��
+ if(pFunList==NULL)
+ {
+ *opstate = OP_STATE_CLOSE;
+ }
+ }
+ //���ӹر�,���״̬
+ else if(*opstate == OP_STATE_CLOSE)
+ {
+ pFunInfo=pFunList;
+ while(pFunInfo)
+ {
+ //add by lqy 20141230
+ //ע�����µ�ֻ����stream_raw���͵ĺ������������ò�һ��
+ //if(pFunInfo->funtype>FUN_TYPE_IPV6_RAW)
+ if(is_raw_cb(pFunInfo->funtype)){
+ ((SAPP_STREAM_FUN_T)pFunInfo->pfun)(a_stream,transport_hdr,raw_pkt,&(pFunInfo->pAppInfo));
+ }else{
+#if 0 //IIEFD_DUAL_STACK
+ /* */
+ if(judge_pure_ipv4_stack(a_stream, this_iphdr) == 1){
+ /* ��IPv4����, ����sapp��� */
+ if((void *)&calltcpApp_old == (void *)pFunInfo->pfun){
+ pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),a_stream->threadnum, this_iphdr);
+ }
+ }else{
+ if((void *)&calltcpApp_old != (void *)pFunInfo->pfun){
+ pFunInfo->appState=((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),a_stream->threadnum, this_iphdr);
+ }
+ }
+#else
+ ((STREAM_CB_FUN_T)pFunInfo->pfun)(a_stream,&(pFunInfo->pAppInfo),threadnum,this_iphdr);
+#endif
+ }
+ pNext=pFunInfo->next;
+ dictator_free(threadnum,pFunInfo);
+
+ pFunInfo=pNext;
+ }
+ *apme=NULL;
+ }
+
+ return ret;
+}
+
+int stream_process_udp_single(struct streaminfo *a_udp,const void * a_packet,void **apme,unsigned char *popstate)
+{
+
+ int i=0;
+ int ret=PASS;
+ char appState=APP_STATE_GIVEME;
+ void *pAppInfo=NULL;
+ int funtype=0;
+
+ for(i=0;i<g_StreamUdpFunNum;i++)
+ {
+ funtype=g_StreamUdpFun[i].funtype;
+ //add by lqy 20141230
+ //ע�����µ�ֻ����stream_raw���͵ĺ������������ò�һ��
+ //if(funtype>FUN_TYPE_IPV6_RAW)
+ if(is_raw_cb(funtype)){
+ appState=g_StreamUdpFun[i].sapp_stream_fun(a_udp,a_packet,a_packet,&(pAppInfo));
+ }else{
+ appState=g_StreamUdpFun[i].stream_fun(a_udp,&(pAppInfo),a_udp->threadnum,a_packet);
+ }
+ if(appState&APP_STATE_DROPPKT)
+ {
+ ret=DROP;
+ break;
+ }
+ }
+ return ret;
+}
+
+#if 0
+/* 2015-12-24 lijia add, ����tcpdetail���ݼ��� */
+static inline void stream_update_tcp_data_count(struct streaminfo *a_tcp)
+{
+ struct tcpdetail *ptcpdetail = a_tcp->ptcpdetail;
+
+ if(NULL == ptcpdetail->pdata){
+ return;
+ }
+
+ if(DIR_C2S == a_tcp->curdir){
+ ptcpdetail->server_data_pkt_num++;
+ ptcpdetail->server_data_bytes += ptcpdetail->datalen;
+ }else{
+ ptcpdetail->client_data_pkt_num++;
+ ptcpdetail->client_data_bytes += ptcpdetail->datalen;
+ }
+}
+#endif
+
+/*
+ lijia 2015-01-12 modify, add this_iphdr,
+ �����IP��Ƭ����İ�, ������ʽ�Ĵ���IP��ͷ, ����ֻ��raw_hdr, �޷���ȡ������IP��ͷ.
+*/
+#if 0
+int stream_process_tcp(struct streaminfo *a_tcp, const raw_pkt_t * a_packet,void **apme,unsigned char *popstate)
+#else
+int stream_process_tcp(struct streaminfo *a_tcp, const void *this_iphdr, const void *transport_hdr,
+ const raw_pkt_t * raw_pkt,void **apme,unsigned char *popstate)
+#endif
+{
+ int ret;
+
+#if 0 /* ����������������ʱ, ��ʱ�ر� */
+ if(PKT_TYPE_NORMAL == a_tcp->addr.pkttype){
+ timestamp_record(TS_LEVEL_BEFORE_PLUG, raw_pkt, a_tcp->threadnum);
+ }
+#endif
+
+ //stream_update_tcp_data_count(a_tcp);
+ /* 2016-07-14 lijia add */
+ if((G_TCP_FLOW_STAT_PROJECT_ID != -1)
+ && (a_tcp->ptcpdetail->datalen > 0)
+ && (STREAM_TYPE_TCP == a_tcp->type)){ /* ��ʹG_TCP_FLOW_STAT_PROJECT_ID����, a_tcp�����Ǵ�����, ��һ����TCP, �˴�Ҫ�ж������� */
+ struct tcpdetail_private *pdetail_pr = (struct tcpdetail_private *)a_tcp->pdetail;
+ if(DIR_C2S == a_tcp->curdir){
+ pdetail_pr->flow_stat->C2S_data_pkt ++;
+ pdetail_pr->flow_stat->C2S_data_byte += a_tcp->ptcpdetail->datalen;
+ }else{
+ pdetail_pr->flow_stat->S2C_data_pkt ++;
+ pdetail_pr->flow_stat->S2C_data_byte += a_tcp->ptcpdetail->datalen;
+ }
+ }
+
+#if (0 == HIGH_PERF)
+ if(a_tcp->addr.pkttype != PKT_TYPE_TCPREORDER){
+ raw_ip_frag_list_stream_attach(a_tcp);
+ }
+#endif
+ ret = stream_process(a_tcp, this_iphdr, transport_hdr, raw_pkt,g_StreamTcpFunNum, g_StreamTcpFun,apme,popstate);
+
+#if (0 == HIGH_PERF)
+ if(a_tcp->addr.pkttype != PKT_TYPE_TCPREORDER){
+ raw_ip_frag_list_stream_detach(a_tcp);
+ }
+#endif
+
+#if 0 /* ����������������ʱ, ��ʱ�ر� */
+ if(PKT_TYPE_NORMAL == a_tcp->addr.pkttype){
+ timestamp_record(TS_LEVEL_AFTER_PLUG, raw_pkt, a_tcp->threadnum);
+ }
+#endif
+ return ret;
+}
+
+/*
+ lijia 2015-01-12 modify, add this_iphdr,
+ �����IP��Ƭ����İ�, ������ʽ�Ĵ���IP��ͷ, ����ֻ��raw_hdr, �޷���ȡ������IP��ͷ.
+*/
+#if 0
+int stream_process_udp(struct streaminfo *a_udp,const raw_pkt_t * a_packet,void **apme,unsigned char *popstate)
+#else
+int stream_process_udp(struct streaminfo *a_udp, const void *this_iphdr, const void *transport_hdr,
+ const raw_pkt_t * raw_pkt,void **apme,unsigned char *popstate)
+#endif
+{
+ int ret;
+
+#if 0 /* ����������������ʱ, ��ʱ�ر� */
+ if(PKT_TYPE_NORMAL == a_udp->addr.pkttype){
+ timestamp_record(TS_LEVEL_BEFORE_PLUG, raw_pkt, a_udp->threadnum);
+ }
+#endif
+
+#if (0 == HIGH_PERF)
+ raw_ip_frag_list_stream_attach(a_udp);
+#endif
+
+ ret = stream_process(a_udp, this_iphdr, transport_hdr,raw_pkt,g_StreamUdpFunNum, g_StreamUdpFun,apme,popstate);
+
+#if (0 == HIGH_PERF)
+ raw_ip_frag_list_stream_detach(a_udp);
+#endif
+
+#if 0 /* ����������������ʱ, ��ʱ�ر� */
+ if(PKT_TYPE_NORMAL == a_udp->addr.pkttype){
+ timestamp_record(TS_LEVEL_AFTER_PLUG, raw_pkt, a_udp->threadnum);
+ }
+#endif
+ return ret;
+}
+
+/*
+ lijia 2015-01-12 modify, add this_iphdr,
+ �����IP��Ƭ����İ�, ������ʽ�Ĵ���IP��ͷ, ����ֻ��raw_hdr, �޷���ȡ������IP��ͷ.
+*/
+#if 0
+int stream_process_tcp_allpkt(struct streaminfo *a_tcp,const raw_pkt_t *a_packet,void **apme,unsigned char *popstate)
+#else
+int stream_process_tcp_allpkt(struct streaminfo *a_tcp,const void *this_iphdr, const void *transport_hdr,
+ const raw_pkt_t *raw_pkt, void **apme,unsigned char *popstate)
+#endif
+{
+ int ret;
+
+#if (0 == HIGH_PERF)
+ raw_ip_frag_list_stream_attach(a_tcp);
+#endif
+
+ ret = stream_process(a_tcp, this_iphdr, transport_hdr, raw_pkt,g_StreamTcpAllFunNum, g_StreamTcpAllFun,apme,popstate);
+
+#if (0 == HIGH_PERF)
+ raw_ip_frag_list_stream_detach(a_tcp);
+#endif
+
+ return ret;
+}
+
+#if 0 /* 20160928 lijia modify, iphdr */
+int stream_process_tcp_takeover(struct streaminfo *a_tcp, const void * raw_pkt)
+{
+ return g_StreamTcpTakeover(a_tcp,NULL,a_tcp->threadnum, raw_pkt);
+}
+#else
+int stream_process_tcp_takeover(struct streaminfo *a_tcp, const void * iphdr)
+{
+ return g_StreamTcpTakeover(a_tcp,NULL,a_tcp->threadnum, iphdr);
+}
+#endif
+
+
+int stream_process_ipv4(struct streaminfo *pfstream, const struct ip* this_layer_hdr,
+ int thread_num,unsigned char routedir, const raw_pkt_t *raw_pkt)
+{
+ int i;
+ //int ret;
+ int appret;
+
+ for(i=0;i<g_Ipv4FunNum;i++)
+ {
+ if(g_Ipv4Fun[i].funtype==FUN_TYPE_IPV4)
+ {
+#if 0 //IIEFD_DUAL_STACK
+ /* */
+ if(judge_pure_ipv4_stack(pfstream, this_layer_hdr) == 1){
+ /* ��IPv4����, ����sapp��� */
+ if((void *)&callIpApp_old != (void *)g_Ipv4Fun[i].stream_ipv4_fun){
+ continue;
+ }
+ }else{
+ /* �Ǵ�IPv4����, ����iiefd��� */
+ if((void *)&callIpApp_old == (void *)g_Ipv4Fun[i].stream_ipv4_fun){
+ continue;
+ }
+ }
+#else
+ appret=g_Ipv4Fun[i].stream_ipv4_fun(pfstream,routedir,thread_num,this_layer_hdr);
+#endif
+ }
+ else
+ {
+ appret=g_Ipv4Fun[i].sapp_pkt_fun(pfstream,this_layer_hdr,raw_pkt);
+ }
+
+ if(unlikely(appret&APP_STATE_DROPPKT))
+ {
+ return DROP;
+ }
+ }
+
+ return PASS;
+}
+
+
+int stream_process_ipv6(struct streaminfo *pfstream,const struct ip6_hdr *this_layer_hdr,
+ int thread_num,unsigned char routedir, const raw_pkt_t *raw_pkt)
+{
+ int i=0;
+ int ret=PASS;
+ int appret=APP_STATE_GIVEME;
+
+ for(i=0;i<g_Ipv6FunNum;i++)
+ {
+ if(g_Ipv6Fun[i].funtype==FUN_TYPE_IPV6)
+ {
+ appret=g_Ipv6Fun[i].stream_ipv6_fun(pfstream,routedir,thread_num,this_layer_hdr);
+ }
+ else
+ {
+ appret=g_Ipv6Fun[i].sapp_pkt_fun(pfstream,this_layer_hdr,raw_pkt);
+ }
+ if(appret&APP_STATE_DROPPKT)
+ {
+ ret=DROP;
+ return ret;
+ }
+ }
+ return ret;
+}
+
+int stream_process_ipv4_frag(struct streaminfo *pstream, const struct ip* this_layer_hdr,
+ int thread_num,unsigned char routedir, const raw_pkt_t *raw_pkt)
+{
+ int i=0;
+ int ret=PASS;
+ int appret=APP_STATE_GIVEME;
+
+ for(i=0;i<g_Ipv4FragFunNum;i++)
+ {
+ if(g_Ipv4FragFun[i].funtype==FUN_TYPE_IPV4_FRAG)
+ {
+ appret=g_Ipv4FragFun[i].stream_ipv4_fun(pstream,routedir,thread_num,this_layer_hdr);
+ }
+ else
+ {
+ appret=g_Ipv4FragFun[i].sapp_pkt_fun(pstream,this_layer_hdr,raw_pkt);
+ }
+
+ if(appret&APP_STATE_DROPPKT)
+ {
+ ret=DROP;
+ return ret;
+ }
+ }
+ return ret;
+}
+
+int stream_process_ipv6_frag(struct streaminfo *pstream,const struct ip6_hdr *this_layer_hdr,
+ int thread_num,unsigned char routedir, const raw_pkt_t *raw_pkt)
+{
+ int i=0;
+ int ret=PASS;
+ int appret=APP_STATE_GIVEME;
+
+ for(i=0;i<g_Ipv6FragFunNum;i++)
+ {
+ if(g_Ipv6FragFun[i].funtype==FUN_TYPE_IPV6_FRAG)
+ {
+ appret=g_Ipv6FragFun[i].stream_ipv6_fun(pstream,routedir,thread_num,this_layer_hdr);
+ }
+ else
+ {
+ appret=g_Ipv6FragFun[i].sapp_pkt_fun(pstream,this_layer_hdr,raw_pkt);
+ }
+ if(appret&APP_STATE_DROPPKT)
+ {
+ ret=DROP;
+ return ret;
+ }
+ }
+ return ret;
+}
+
+/*
+ 2016-09-26 lijia add,
+ û�а�ʱ, ���������,
+ ����������, �ײ��ղ�����ʱ, Ҳ����ò��, ʹ����ܼ�ʱ���CPU, ��һЩ�ǰ������Ĵ����߼�.
+*/
+int stream_process_polling(int thread_seq)
+{
+ int i;
+
+ for(i = 0; i < g_PollingFunNum; i++){
+ g_PollingFun[i].stream_fun(NULL, NULL, thread_seq, NULL);
+ }
+
+ return 0;
+}
+
+extern int g_use_MESA_sleep_sw;
+extern void MESA_sleep(void);
+/*
+ 2016-09-26 lijia add,
+ �ײ�����û�а�ʱ, ����ô˺���, ����ƽ̨�����Ƿ������ȴ�, ���ǵ����ϲ���ѯ���.
+*/
+void idle_polling_call(int thread_seq)
+{
+ if(0 == g_PollingFunNum){
+ return;
+ }else{
+ stream_process_polling(thread_seq);
+ }
+
+ return;
+}
+
+#if 0 /* ���ò��ʵ�� */
+static inline int is_raw_cb(int cb_type)
+{
+ int ret;
+
+ switch(cb_type){
+ case FUN_TYPE_IPV4:
+ case FUN_TYPE_IPV4_FRAG:
+ case FUN_TYPE_IPV6:
+ case FUN_TYPE_IPV6_FRAG:
+ case FUN_TYPE_TCP:
+ case FUN_TYPE_TCPALL:
+ case FUN_TYPE_UDP:
+ ret = 0;
+ break;
+
+ case FUN_TYPE_IPV4_RAW:
+ case FUN_TYPE_IPV4_FRAG_RAW:
+ case FUN_TYPE_IPV6_RAW:
+ case FUN_TYPE_IPV6_FRAG_RAW:
+ case FUN_TYPE_TCP_RAW:
+ case FUN_TYPE_TCPALL_RAW:
+ case FUN_TYPE_UDP_RAW:
+ ret = 1;
+ break;
+
+ default:
+ assert(0);
+ }
+
+ return ret;
+}
+#else
+typedef struct
+{
+ enum fun_type_t funtype;
+ int is_raw;
+}raw_cb_fun_identify_t;
+
+const static raw_cb_fun_identify_t g_raw_cb_fun_identify_array[__FUN_TYPE_MAX] =
+{
+ {FUN_TYPE_IPV4, 0},
+ {FUN_TYPE_IPV6, 0},
+ {FUN_TYPE_TCP, 0},
+ {FUN_TYPE_TCPALL, 0},
+ {FUN_TYPE_UDP, 0},
+ {FUN_TYPE_IPV4_RAW, 1},
+ {FUN_TYPE_IPV6_RAW, 1},
+ {FUN_TYPE_TCP_RAW, 1},
+ {FUN_TYPE_TCPALL_RAW, 1},
+ {FUN_TYPE_UDP_RAW, 1},
+ {FUN_TYPE_IPV4_FRAG, 0},
+ {FUN_TYPE_IPV4_FRAG_RAW, 1},
+ {FUN_TYPE_IPV6_FRAG, 0},
+ {FUN_TYPE_IPV6_FRAG_RAW, 1},
+
+};
+
+static inline int is_raw_cb(int cb_type)
+{
+ assert(cb_type < __FUN_TYPE_MAX);
+ return g_raw_cb_fun_identify_array[cb_type].is_raw;
+}
+#endif
+
+
+
+#ifdef IIEFD_DUAL_STACK
+/* 2015-09-02 lijia add, for iieqd_dual_stack */
+static int judge_pure_ipv4_stack(const struct streaminfo *pstream, const void *a_packet)
+{
+ int ret = 0;
+ const mesa_ip4_hdr *ip4_hdr = (const mesa_ip4_hdr *)a_packet;
+
+ switch(pstream->addr.addrtype){
+ case __ADDR_TYPE_IP_PAIR_V4:
+ if((IPPROTO_TCP != ip4_hdr->ip_p) && (IPPROTO_UDP != ip4_hdr->ip_p)){
+ ret = 0;
+ break;
+ }
+ if((NULL == pstream->pfather)
+ ||((NULL != pstream->pfather) && (ADDR_TYPE_MAC == pstream->pfather->addr.addrtype))){
+ ret = 1;
+ }else{
+ ret = 0;
+ }
+ break;
+
+ case ADDR_TYPE_IPV4:
+ if(__ADDR_TYPE_IP_PAIR_V4 != pstream->pfather->addr.addrtype){
+ ret = 0;
+ break;
+ }
+
+ if((pstream->pfather->pfather != NULL) && (ADDR_TYPE_MAC != pstream->pfather->pfather->addr.addrtype)){
+ ret = 0;
+ break;
+ }
+
+ ret = 1;
+ break;
+
+ default:
+ ret = 0;
+ break;
+ }
+
+ return ret;
+}
+#endif
+
+ int g_packet_io_ipv6_switch = 0;
+ extern int g_discard_ack_sw;
+ int app_function_rationality_check(void)
+{
+ /* 2015-01-12 lijia add, for error message */
+ if((0 == tcp_support_all) && (g_StreamTcpAllFunNum != 0)){
+ printf("\033[33m[Warning]You have registered 'TCP_ALL' plugin, but 'TcpAllEnable' in main.conf is disable! \033[0m\n");
+ sleep(1);
+ }
+
+ if((0 == g_packet_io_ipv6_switch) && (g_Ipv6FunNum != 0)){
+ printf("\033[33m[Warning]You have registered 'IPV6' plugin, but 'IPv6_module_enable' in main.conf is disable! \033[0m\n");
+ sleep(1);
+ }
+
+ if((0 != tcp_support_all) && (g_discard_ack_sw != 0)){
+#if HIGH_PERF
+ printf("\033[33m[Warning]Config conflict! 'TcpAllEnable' and 'discard_ack' is all enable, but in high-perf mode, discard_ack is keep enable!\033[0m\n");
+#else
+ printf("\033[33m[Warning]Config conflict! 'TcpAllEnable' and 'discard_ack' is all enable, TCPALL plug can't get ACK pkt.\033[0m\n");
+#endif
+ sleep(1);
+ }
+
+ return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/dealpkt/deal_ethernet.c b/dealpkt/deal_ethernet.c
index 9043c04..00004e8 100644
--- a/dealpkt/deal_ethernet.c
+++ b/dealpkt/deal_ethernet.c
@@ -1,248 +1,248 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <pthread.h>
-#include <netinet/ip.h>
-#include <netinet/ip6.h>
-#include <linux/if_ether.h>
-#include "stream_manage.h"
-#include "sendpacket.h"
-#include "deal_ipv6.h"
-#include "packet_io.h"
-#include "mesa_net.h"
-#include "sysinfo.h"
-#include "stream_internal.h"
-#include "packet_io_internal.h"
-
-#if DEBUG
-#include "iknow.h"
-extern packet_io_status_t *g_packet_io_status_pool[MAX_THREAD_NUM];
-extern int g_packet_io_thread_num;
-static inline void packet_io_eth_status_update(int thread_seq, int raw_pkt_len);
-#endif
-
-static const unsigned char G_BROADCAST_ADDR[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
-
-extern int g_topology_mode;
-extern int g_skip_ethernet_layer_sw;
-
-static inline void set_mac_addr(struct layer_addr_mac *addr, const struct mesa_ethernet_hdr *p_eth_hdr)
-{
- memcpy(&(addr->dst_mac[0]), &(p_eth_hdr->ether_dhost[0]), ETHER_ADDR_LEN);
- memcpy(&(addr->src_mac[0]), &(p_eth_hdr->ether_shost[0]), ETHER_ADDR_LEN);
-}
-
-
-int eth_entry(struct streaminfo_private *fstream_pr, const void *this_layer_hdr,int thread_num,
- unsigned char dir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr)
-{
- int ret;
- const unsigned char *next_layer_data = (const unsigned char *)this_layer_hdr + sizeof(struct mesa_ethernet_hdr);
- const struct mesa_ethernet_hdr *p_eth_hdr = (const struct mesa_ethernet_hdr *)this_layer_hdr;
- //unsigned short eth_type = ntohs(p_eth_hdr->ether_type);
- unsigned short eth_type = ntohs(p_eth_hdr->ether_type); /* ʹ��������ֱ���ж�, ����ÿ�ζ�����ntohs() */
- int next_layer_offset;
- struct streamindex tmp_index;
- struct streamindex *ptmp;
- struct streaminfo_private *pstream_pr;
- struct streaminfo *pstream;
-
- if(g_topology_mode & __NET_CONN_GDEV){
- if(memcmp(G_BROADCAST_ADDR, p_eth_hdr->ether_dhost, 6) == 0){
- /* G����ģʽ�£���ARPЭ��Ĺ㲥����ֱ�Ӷ���! ��ֹ�ٻ�ע��������, ��ɹ㲥�籩���������� */
- if(eth_type != ETH_P_ARP){
- return DROP;
- }
- }else{
- /* 2017-10-10 lijia add, �鲥MAC��ַ, ͨ��Ϊ�������ڿ��������ݰ�, ��LLMNR, SPT��Э��, һ�����账��, Ҳ����ת�� */
- if((p_eth_hdr->ether_dhost[0] & 0x01) == 0x01){
- return DROP;
- }
- }
- }
-
- if(unlikely(0 == g_skip_ethernet_layer_sw)){
- ptmp = &tmp_index;
- pstream_pr = &ptmp->stream;
- pstream = &pstream_pr->stream_public;
- next_layer_offset = offset_to_raw_pkt_hdr + sizeof(struct mesa_ethernet_hdr);
-
-#if DEBUG
- packet_io_eth_status_update(thread_num, raw_pkt->raw_pkt_len);
-#endif
- memset(ptmp, 0, sizeof(struct streamindex));
- //set_mac_addr(&addr, p_eth_hdr);
- pstream->addr.mac = (struct layer_addr_mac *)this_layer_hdr;
- pstream->addr.addrlen = sizeof(struct layer_addr_mac);
- pstream->addr.addrtype = ADDR_TYPE_MAC;
- pstream_pr->addr_use_as_hash = 0;
- //ptmp->stream.p_layer_header = this_layer_hdr;
- //ptmp->stream.offset_to_raw_pkt_hdr = (char *)this_layer_hdr - (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->pfather = (struct streaminfo *)fstream_pr;
- pstream->type = STREAM_TYPE_NON;
- pstream->routedir = dir;
- pstream->threadnum = thread_num;
- /* LiJia add, ��Ϊ����һ������, ��ΪԴ��ַ�����ΪClient�� */
- if(memcmp(p_eth_hdr->ether_shost, p_eth_hdr->ether_dhost, ETHER_ADDR_LEN) >= 0){
- pstream_pr->layer_dir = 1;
- pstream->curdir = DIR_C2S;
- }else{
- pstream_pr->layer_dir = 0;
- pstream->curdir = DIR_S2C;
- }
-
- g_SysInputInfo[thread_num][PKT_ETHERNET]++;
- g_SysInputInfo[thread_num][PKT_ETHERNET_LEN] += (unsigned long long)raw_pkt->raw_pkt_len;
- }else{
- pstream_pr = NULL; /* ʹ�ϲ����Э���pfatherΪNULL */
- next_layer_offset = 0;
- if((int)CAP_LEVEL_MAC == (int)raw_pkt->low_layer_type){
- ((raw_pkt_t *)raw_pkt)->raw_pkt_data = (char *)raw_pkt->__lib_raw_pkt_data + sizeof(struct mesa_ethernet_hdr);
- ((raw_pkt_t *)raw_pkt)->raw_pkt_len = raw_pkt->__lib_raw_pkt_len - sizeof(struct mesa_ethernet_hdr);
- }
- }
- if(sapp_global_single.create_mpls_anyway != 0)
- {
- if(eth_type == ETHERTYPE_IP || eth_type == ETHERTYPE_IPv6)
- {
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret = mpls_empty_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
- }
- }
- else
- {
- switch(eth_type){
- case ETHERTYPE_IP:
- if(g_skip_ethernet_layer_sw){
- ((raw_pkt_t *)raw_pkt)->low_layer_type = (enum addr_type_t)CAP_LEVEL_IPV4;
- }
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret = ipv4_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
- break;
-
- case ETHERTYPE_IPv6:
- if(g_skip_ethernet_layer_sw){
- ((raw_pkt_t *)raw_pkt)->low_layer_type = (enum addr_type_t)CAP_LEVEL_IPV6;
- }
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret = ipv6_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
- break;
-
- case ETHERTYPE_VLAN:
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- if(sapp_global_single.treat_vlan_as_mac_in_mac_sw){
- ret = mac_in_mac_entry(pstream_pr,next_layer_data,thread_num,dir,raw_pkt, next_layer_offset);
- }else{
- ret = vlan_8021q_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
- }
- break;
-
- case ETH_P_PPP_SES:
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret = pppoe_session_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
- break;
-
- case ETH_P_MPLS_UC: /* 2014-12-08 add */
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret = mpls_uc_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
- break;
-
- case ETH_P_ARP:
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret = arp_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
- break;
-
- /* 2018-08-19 lijia add, for PanGu��Ŀ��������������ʽ, ������ETH_P_8021AD(0x88A8)�ֶ�, ʵ����MAC-IN-MAC��ʽ���ݰ� */
- case ETH_P_MAC_IN_MAC:
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret = mac_in_mac_entry(pstream_pr,next_layer_data,thread_num,dir,raw_pkt, next_layer_offset);
- break;
-
- default:
- /* unknown protocol */
- g_SysInputInfo[thread_num][PKT_UNKNOWN]++;
- g_SysInputInfo[thread_num][PKT_UNKNOWN_LEN] += raw_pkt->raw_pkt_len;
- if(NET_CONN_SERIAL_GDEV == g_topology_mode){
- /* GDEV����ģʽ��, ʲôʱ�򶼲�Ӧ�ðѲ���ʶ�İ��ٻ�ע, ���߷��ְ�SPT������Э����ע��ȥ, ����������� */
- ret = DROP;
- }else{
- ret = PASS;
- }
- break;
- }
- }
-
- return ret;
-}
-
-#if DEBUG
-static packet_io_status_base_t g_io_eth_last_status, g_io_eth_cur_status, g_io_eth_realtime_status;
-long ifuncb_show_eth_summary(iknow_handle ihandle, iknow_conn iconn, const void *cb_fun_arg, const char *cmd_args)
-{
- iprintf(ihandle, iconn,"NOTE: unit of byte for total is 'byte', for realtime is 'bps, bit per second'!\n");
- iprintf(ihandle, iconn, "%8s %8s %12s\n", " ", "packet", "byte");
- iprintf(ihandle, iconn, "%8s %8llu %12llu\n%8s %8llu %12llu\n",
- "total", g_io_eth_cur_status.pkt_num, g_io_eth_cur_status.pkt_byte,
- "realtime", g_io_eth_realtime_status.pkt_num, g_io_eth_realtime_status.pkt_byte*8);
-
- return 0;
-}
-
-void *packet_io_status_eth_mem_init(void)
-{
- void *eth_mem;
-
- eth_mem = malloc(sizeof(packet_io_status_base_t));
- memset(eth_mem, 0, sizeof(packet_io_status_base_t));
-
- return eth_mem;
-}
-
-void iknow_register_eth_cb(void *ihandle)
-{
- int ret;
-
- ret = iknow_register_cmd(ihandle, "show eth summary", "display eth flow summary", ifuncb_show_eth_summary, NULL, 0, NULL);
- assert(0 == ret);
-}
-
-static inline void packet_io_eth_status_update(int thread_seq, int raw_pkt_len)
-{
- packet_io_status_base_t *p_eth_status;
-
- p_eth_status = (packet_io_status_base_t *)(g_packet_io_status_pool[thread_seq]->packet_io_status[IO_STATUS_ETH]);
-
- p_eth_status->pkt_num++;
- p_eth_status->pkt_byte += raw_pkt_len;
-}
-
-void packet_io_status_eth_time_cb(void)
-{
- /* ȫ���ܰ���, ���ֽ���, ƽ������, ��ǰʵʱ���� */
- int i;
- packet_io_status_base_t *p_eth_status;
-
- memcpy((void *)&g_io_eth_last_status, (void *)&g_io_eth_cur_status, sizeof(packet_io_status_base_t)); /* ������һ���ֵ */
- memset((void *)&g_io_eth_cur_status, 0, sizeof(packet_io_status_base_t)); /* ���� */
-
- for(i = 0; i < g_packet_io_thread_num; i++){
- p_eth_status = (packet_io_status_base_t *)(g_packet_io_status_pool[i]->packet_io_status[IO_STATUS_ETH]);
- g_io_eth_cur_status.pkt_num += p_eth_status->pkt_num;
- g_io_eth_cur_status.pkt_byte += p_eth_status->pkt_byte;
- }
-
- g_io_eth_realtime_status.pkt_num = g_io_eth_cur_status.pkt_num - g_io_eth_last_status.pkt_num;
- g_io_eth_realtime_status.pkt_byte = g_io_eth_cur_status.pkt_byte - g_io_eth_last_status.pkt_byte;
-}
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <netinet/ip.h>
+#include <netinet/ip6.h>
+#include <linux/if_ether.h>
+#include "stream_manage.h"
+#include "sendpacket.h"
+#include "deal_ipv6.h"
+#include "packet_io.h"
+#include "mesa_net.h"
+#include "sysinfo.h"
+#include "stream_internal.h"
+#include "packet_io_internal.h"
+
+#if DEBUG
+#include "iknow.h"
+extern packet_io_status_t *g_packet_io_status_pool[MAX_THREAD_NUM];
+extern int g_packet_io_thread_num;
+static inline void packet_io_eth_status_update(int thread_seq, int raw_pkt_len);
+#endif
+
+static const unsigned char G_BROADCAST_ADDR[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+
+extern int g_topology_mode;
+extern int g_skip_ethernet_layer_sw;
+
+static inline void set_mac_addr(struct layer_addr_mac *addr, const struct mesa_ethernet_hdr *p_eth_hdr)
+{
+ memcpy(&(addr->dst_mac[0]), &(p_eth_hdr->ether_dhost[0]), ETHER_ADDR_LEN);
+ memcpy(&(addr->src_mac[0]), &(p_eth_hdr->ether_shost[0]), ETHER_ADDR_LEN);
+}
+
+
+int eth_entry(struct streaminfo_private *fstream_pr, const void *this_layer_hdr,int thread_num,
+ unsigned char dir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr)
+{
+ int ret;
+ const unsigned char *next_layer_data = (const unsigned char *)this_layer_hdr + sizeof(struct mesa_ethernet_hdr);
+ const struct mesa_ethernet_hdr *p_eth_hdr = (const struct mesa_ethernet_hdr *)this_layer_hdr;
+ //unsigned short eth_type = ntohs(p_eth_hdr->ether_type);
+ unsigned short eth_type = ntohs(p_eth_hdr->ether_type); /* ʹ��������ֱ���ж�, ����ÿ�ζ�����ntohs() */
+ int next_layer_offset;
+ struct streamindex tmp_index;
+ struct streamindex *ptmp;
+ struct streaminfo_private *pstream_pr;
+ struct streaminfo *pstream;
+
+ if(g_topology_mode & __NET_CONN_GDEV){
+ if(memcmp(G_BROADCAST_ADDR, p_eth_hdr->ether_dhost, 6) == 0){
+ /* G����ģʽ�£���ARPЭ��Ĺ㲥����ֱ�Ӷ���! ��ֹ�ٻ�ע��������, ��ɹ㲥�籩���������� */
+ if(eth_type != ETH_P_ARP){
+ return DROP;
+ }
+ }else{
+ /* 2017-10-10 lijia add, �鲥MAC��ַ, ͨ��Ϊ�������ڿ��������ݰ�, ��LLMNR, SPT��Э��, һ�����账��, Ҳ����ת�� */
+ if((p_eth_hdr->ether_dhost[0] & 0x01) == 0x01){
+ return DROP;
+ }
+ }
+ }
+
+ if(unlikely(0 == g_skip_ethernet_layer_sw)){
+ ptmp = &tmp_index;
+ pstream_pr = &ptmp->stream;
+ pstream = &pstream_pr->stream_public;
+ next_layer_offset = offset_to_raw_pkt_hdr + sizeof(struct mesa_ethernet_hdr);
+
+#if DEBUG
+ packet_io_eth_status_update(thread_num, raw_pkt->raw_pkt_len);
+#endif
+ memset(ptmp, 0, sizeof(struct streamindex));
+ //set_mac_addr(&addr, p_eth_hdr);
+ pstream->addr.mac = (struct layer_addr_mac *)this_layer_hdr;
+ pstream->addr.addrlen = sizeof(struct layer_addr_mac);
+ pstream->addr.addrtype = ADDR_TYPE_MAC;
+ pstream_pr->addr_use_as_hash = 0;
+ //ptmp->stream.p_layer_header = this_layer_hdr;
+ //ptmp->stream.offset_to_raw_pkt_hdr = (char *)this_layer_hdr - (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->pfather = (struct streaminfo *)fstream_pr;
+ pstream->type = STREAM_TYPE_NON;
+ pstream->routedir = dir;
+ pstream->threadnum = thread_num;
+ /* LiJia add, ��Ϊ����һ������, ��ΪԴ��ַ�����ΪClient�� */
+ if(memcmp(p_eth_hdr->ether_shost, p_eth_hdr->ether_dhost, ETHER_ADDR_LEN) >= 0){
+ pstream_pr->layer_dir = 1;
+ pstream->curdir = DIR_C2S;
+ }else{
+ pstream_pr->layer_dir = 0;
+ pstream->curdir = DIR_S2C;
+ }
+
+ g_SysInputInfo[thread_num][PKT_ETHERNET]++;
+ g_SysInputInfo[thread_num][PKT_ETHERNET_LEN] += (unsigned long long)raw_pkt->raw_pkt_len;
+ }else{
+ pstream_pr = NULL; /* ʹ�ϲ����Э���pfatherΪNULL */
+ next_layer_offset = 0;
+ if((int)CAP_LEVEL_MAC == (int)raw_pkt->low_layer_type){
+ ((raw_pkt_t *)raw_pkt)->raw_pkt_data = (char *)raw_pkt->__lib_raw_pkt_data + sizeof(struct mesa_ethernet_hdr);
+ ((raw_pkt_t *)raw_pkt)->raw_pkt_len = raw_pkt->__lib_raw_pkt_len - sizeof(struct mesa_ethernet_hdr);
+ }
+ }
+ if(sapp_global_single.create_mpls_anyway != 0)
+ {
+ if(eth_type == ETHERTYPE_IP || eth_type == ETHERTYPE_IPv6)
+ {
+ ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
+ ret = mpls_empty_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
+ }
+ }
+ else
+ {
+ switch(eth_type){
+ case ETHERTYPE_IP:
+ if(g_skip_ethernet_layer_sw){
+ ((raw_pkt_t *)raw_pkt)->low_layer_type = (enum addr_type_t)CAP_LEVEL_IPV4;
+ }
+ ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
+ ret = ipv4_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
+ break;
+
+ case ETHERTYPE_IPv6:
+ if(g_skip_ethernet_layer_sw){
+ ((raw_pkt_t *)raw_pkt)->low_layer_type = (enum addr_type_t)CAP_LEVEL_IPV6;
+ }
+ ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
+ ret = ipv6_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
+ break;
+
+ case ETHERTYPE_VLAN:
+ ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
+ if(sapp_global_single.treat_vlan_as_mac_in_mac_sw){
+ ret = mac_in_mac_entry(pstream_pr,next_layer_data,thread_num,dir,raw_pkt, next_layer_offset);
+ }else{
+ ret = vlan_8021q_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
+ }
+ break;
+
+ case ETH_P_PPP_SES:
+ ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
+ ret = pppoe_session_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
+ break;
+
+ case ETH_P_MPLS_UC: /* 2014-12-08 add */
+ ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
+ ret = mpls_uc_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
+ break;
+
+ case ETH_P_ARP:
+ ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
+ ret = arp_entry(pstream_pr, (const void *)next_layer_data, thread_num, dir, raw_pkt, next_layer_offset);
+ break;
+
+ /* 2018-08-19 lijia add, for PanGu��Ŀ��������������ʽ, ������ETH_P_8021AD(0x88A8)�ֶ�, ʵ����MAC-IN-MAC��ʽ���ݰ� */
+ case ETH_P_MAC_IN_MAC:
+ ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
+ ret = mac_in_mac_entry(pstream_pr,next_layer_data,thread_num,dir,raw_pkt, next_layer_offset);
+ break;
+
+ default:
+ /* unknown protocol */
+ g_SysInputInfo[thread_num][PKT_UNKNOWN]++;
+ g_SysInputInfo[thread_num][PKT_UNKNOWN_LEN] += raw_pkt->raw_pkt_len;
+ if(NET_CONN_SERIAL_GDEV == g_topology_mode){
+ /* GDEV����ģʽ��, ʲôʱ�򶼲�Ӧ�ðѲ���ʶ�İ��ٻ�ע, ���߷��ְ�SPT������Э����ע��ȥ, ����������� */
+ ret = DROP;
+ }else{
+ ret = PASS;
+ }
+ break;
+ }
+ }
+
+ return ret;
+}
+
+#if DEBUG
+static packet_io_status_base_t g_io_eth_last_status, g_io_eth_cur_status, g_io_eth_realtime_status;
+long ifuncb_show_eth_summary(iknow_handle ihandle, iknow_conn iconn, const void *cb_fun_arg, const char *cmd_args)
+{
+ iprintf(ihandle, iconn,"NOTE: unit of byte for total is 'byte', for realtime is 'bps, bit per second'!\n");
+ iprintf(ihandle, iconn, "%8s %8s %12s\n", " ", "packet", "byte");
+ iprintf(ihandle, iconn, "%8s %8llu %12llu\n%8s %8llu %12llu\n",
+ "total", g_io_eth_cur_status.pkt_num, g_io_eth_cur_status.pkt_byte,
+ "realtime", g_io_eth_realtime_status.pkt_num, g_io_eth_realtime_status.pkt_byte*8);
+
+ return 0;
+}
+
+void *packet_io_status_eth_mem_init(void)
+{
+ void *eth_mem;
+
+ eth_mem = malloc(sizeof(packet_io_status_base_t));
+ memset(eth_mem, 0, sizeof(packet_io_status_base_t));
+
+ return eth_mem;
+}
+
+void iknow_register_eth_cb(void *ihandle)
+{
+ int ret;
+
+ ret = iknow_register_cmd(ihandle, "show eth summary", "display eth flow summary", ifuncb_show_eth_summary, NULL, 0, NULL);
+ //assert(0 == ret);
+}
+
+static inline void packet_io_eth_status_update(int thread_seq, int raw_pkt_len)
+{
+ packet_io_status_base_t *p_eth_status;
+
+ p_eth_status = (packet_io_status_base_t *)(g_packet_io_status_pool[thread_seq]->packet_io_status[IO_STATUS_ETH]);
+
+ p_eth_status->pkt_num++;
+ p_eth_status->pkt_byte += raw_pkt_len;
+}
+
+void packet_io_status_eth_time_cb(void)
+{
+ /* ȫ���ܰ���, ���ֽ���, ƽ������, ��ǰʵʱ���� */
+ int i;
+ packet_io_status_base_t *p_eth_status;
+
+ memcpy((void *)&g_io_eth_last_status, (void *)&g_io_eth_cur_status, sizeof(packet_io_status_base_t)); /* ������һ���ֵ */
+ memset((void *)&g_io_eth_cur_status, 0, sizeof(packet_io_status_base_t)); /* ���� */
+
+ for(i = 0; i < g_packet_io_thread_num; i++){
+ p_eth_status = (packet_io_status_base_t *)(g_packet_io_status_pool[i]->packet_io_status[IO_STATUS_ETH]);
+ g_io_eth_cur_status.pkt_num += p_eth_status->pkt_num;
+ g_io_eth_cur_status.pkt_byte += p_eth_status->pkt_byte;
+ }
+
+ g_io_eth_realtime_status.pkt_num = g_io_eth_cur_status.pkt_num - g_io_eth_last_status.pkt_num;
+ g_io_eth_realtime_status.pkt_byte = g_io_eth_cur_status.pkt_byte - g_io_eth_last_status.pkt_byte;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/dealpkt/deal_tcp.c b/dealpkt/deal_tcp.c
index f0eec88..c4a8c8a 100644
--- a/dealpkt/deal_tcp.c
+++ b/dealpkt/deal_tcp.c
@@ -3421,11 +3421,11 @@ void iknow_register_tcp_pkt_cb(void *ihandle)
int ret;
ret = iknow_register_cmd(ihandle, "show tcp pkt summary", "display tcp pkt summary", ifuncb_show_tcp_pkt_summary, NULL, 0, NULL);
- assert(0 == ret);
+ //assert(0 == ret);
ret = iknow_register_cmd(ihandle, "show tcp pkt detail total", "display tcp pkt detail total", ifuncb_show_tcp_pkt_detail_total, NULL, 0, NULL);
- assert(0 == ret);
+ //assert(0 == ret);
ret = iknow_register_cmd(ihandle, "show tcp pkt detail realtime", "display tcp pkt detail realtime", ifuncb_show_tcp_pkt_detail_realtime, NULL, 0, NULL);
- assert(0 == ret);
+ //assert(0 == ret);
}
void *packet_io_status_tcp_stream_mem_init(void)
@@ -3508,7 +3508,7 @@ void iknow_register_tcp_stream_cb(void *ihandle)
int ret;
ret = iknow_register_cmd(ihandle, "show tcp stream summary", "display tcp stream summary", ifuncb_show_tcp_stream_summary, NULL, 0, NULL);
- assert(0 == ret);
+ //assert(0 == ret);
//ret = iknow_register_cmd(ihandle, "show tcp stream detail total", "display tcp stream detail total", ifuncb_show_tcp_stream_detail, NULL, 0, NULL);
//assert(0 == ret);
//ret = iknow_register_cmd(ihandle, "show tcp stream detail realtime", "display tcp stream detail realtime", ifuncb_show_tcp_stream_detail, NULL, 0, NULL);
diff --git a/dealpkt/deal_vlan.c b/dealpkt/deal_vlan.c
index b749567..472c4b7 100644
--- a/dealpkt/deal_vlan.c
+++ b/dealpkt/deal_vlan.c
@@ -1,225 +1,225 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "stream_internal.h"
-#include "sendpacket.h"
-#include "stream_manage.h"
-#include "packet_io.h"
-#include "packet_io_internal.h"
-#include <linux/if_ether.h>
-
-#define VLAN_ID_MAX (4096) /* vlan id is 12bit, max is 4096 */
-
-#if DEBUG
-static inline void packet_io_vlan_status_update(int thread_seq, const struct layer_addr_vlan *addr, int raw_pkt_len);
-#endif
-
-static inline void set_vlanid(struct layer_addr_vlan *addr, unsigned short *vlan_tag)
-{
- addr->vlan_id = ntohs(*vlan_tag) & VLAN_ID_MASK;
- return;
-}
-
-int vlan_8021q_entry(struct streaminfo_private *pfstream_pr,const void *this_layer_data,int thread_num,
- unsigned char routedir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr)
-{
- int ret = PASS;
- struct streamindex tmp_index;
- struct streamindex *ptmp=&tmp_index;
- struct streaminfo_private *pstream_pr = &ptmp->stream;
- struct streaminfo *pstream = &pstream_pr->stream_public;
- struct layer_addr_vlan addr;
- u_short ether_type;
- char *next_layer_hdr = (char *)this_layer_data+ VLAN_TAG_LEN;
- int next_layer_offset = offset_to_raw_pkt_hdr + VLAN_TAG_LEN;
-
- if(unlikely(0 == G_SKIP_NOT_IP_LAYER)){
- memset(ptmp,0,sizeof(struct streamindex));
- set_vlanid(&addr, (unsigned short *)this_layer_data);
-#if DEBUG
- packet_io_vlan_status_update(thread_num, &addr, raw_pkt->raw_pkt_len);
-#endif
- pstream->addr.paddr=&addr;
- pstream->addr.addrtype = ADDR_TYPE_VLAN;
- pstream->addr.addrlen = sizeof(struct layer_addr_vlan);
- pstream_pr->addr_use_as_hash = 1;
- //ptmp->stream.p_layer_header = this_layer_data;
- //ptmp->stream.offset_to_raw_pkt_hdr = (char *)this_layer_data - (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->pfather=&pfstream_pr->stream_public;
- pstream->type=STREAM_TYPE_NON;
- pstream->routedir=routedir;
- pstream->threadnum=thread_num;
- }else{
- pstream_pr = pfstream_pr; /* 2015-07-03 lijia add, skip this layer */
- }
-
- ether_type=*((unsigned short *)((char *)this_layer_data + 2));
- ether_type = ntohs(ether_type);
-
- switch(ether_type)
- {
- case ETH_P_IP:
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret=ipv4_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset);
- break;
- case ETH_P_IPV6:
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret=ipv6_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset);
- break;
-
- case ETH_P_8021Q:
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret=vlan_8021q_entry(pstream_pr, next_layer_hdr,thread_num, routedir,raw_pkt, next_layer_offset);
- break;
-
- case ETH_P_PPP_SES:
-#if COMPAT_PAPP_FOR_BENCHMARK
- return PASS;
-#endif
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret=pppoe_session_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset);
- break;
-
- case ETH_P_MPLS_UC:
- case ETH_P_MPLS_MC:
- ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
- ret = mpls_uc_entry(pstream_pr, (const void *)next_layer_hdr, thread_num, routedir, raw_pkt, next_layer_offset);
- break;
-
- default:
- /* unknown protocol */
- g_SysInputInfo[thread_num][PKT_UNKNOWN]++;
- g_SysInputInfo[thread_num][PKT_UNKNOWN_LEN] += raw_pkt->raw_pkt_len;
-
- sapp_runtime_log(20, "VLAN unknown protocol: 0x%x\n", ether_type);
-
- if(NET_CONN_SERIAL_GDEV == g_topology_mode){
- /* GDEVģʽ��, ʲôʱ�򶼲�Ӧ�ðѲ���ʶ�İ���ת����ȥ, ���߷��ְ�SPT������Э����ע��ȥ, ����������� */
- ret = DROP;
- }else{
- ret = PASS;
- }
- break;
- }
-
- return ret;
-}
-
-#if DEBUG
-#include "iknow.h"
-
-extern int g_packet_io_thread_num;
-extern packet_io_status_t *g_packet_io_status_pool[MAX_THREAD_NUM];
-
-/*
- sysinfo֮ǰ�Ǽ򵥶�ά����, ���ܱ�ʾ���̡߳���Э�顢��Э��ľ������.
-
- �µļܹ���, ÿ��Э�������ṹ, ��packet_io_status_base_t��������չ,
- ��֮ǰ��sysinfo�ļ򵥶�ά���鲻ͬ,
- �½ṹÿ��Э��洢�����Ͳ�ͬ, �ṹҲ��ͬ,
- �߼�����, �ڴ�ʹ�����Ż�.
-*/
-typedef struct{
- packet_io_status_base_t io_base_status; /* VLAN���ܼ��� */
- unsigned long long vlan_pkt_num[VLAN_ID_MAX]; /* ÿ��VLAN�İ��� */
- unsigned long long vlan_pkt_byte[VLAN_ID_MAX]; /* ÿ��VLAN���ֽ��� */
-}packet_io_status_vlan_t;
-
-/* ����: ��һ��:1000B, ��ǰ:5000B, �ɼ�������һ���ʵʱ����:4000B/s */
-static volatile packet_io_status_vlan_t g_io_vlan_last_status, g_io_vlan_cur_status, g_io_vlan_realtime_status;
-
-static long ifuncb_show_vlan_id_summary(iknow_handle ihandle, iknow_conn iconn, const void *cb_fun_arg,const char *cmd_args)
-{
- int i;
- /* ȫ��vlan-id�ܰ���, ���ֽ��� */
- iprintf(ihandle, iconn, "vlan id summary:\n %7s %9s %10s\n", "VLAN-ID", "Total-pkt", "Total-byte");
- for(i = 0; i < VLAN_ID_MAX; i++){
- if(g_io_vlan_cur_status.vlan_pkt_num[i] > 0){
- iprintf(ihandle, iconn, "%7d %9llu %10llu\n", i, g_io_vlan_cur_status.vlan_pkt_num[i], g_io_vlan_cur_status.vlan_pkt_byte[i] );
- }
- }
-
- return 0;
-}
-
-static long ifuncb_show_vlan_summary(iknow_handle ihandle, iknow_conn iconn, const void *cb_fun_arg, const char *cmd_args)
-{
- /* ȫ���ܰ���, ���ֽ��� */
- iprintf(ihandle, iconn,"NOTE: unit of byte for total is 'byte', for realtime is 'bps, bit per second'!\n");
- iprintf(ihandle, iconn, "%8s %8s %12s\n", " ", "packet", "byte");
- iprintf(ihandle, iconn, "%8s %8llu %12llu\n%8s %8llu %12llu\n",
- "total", g_io_vlan_cur_status.io_base_status.pkt_num, g_io_vlan_cur_status.io_base_status.pkt_byte,
- "realtime", g_io_vlan_realtime_status.io_base_status.pkt_num, g_io_vlan_realtime_status.io_base_status.pkt_byte*8);
-
- return 0;
-}
-
-void iknow_register_vlan_cb(void *ihandle)
-{
- int ret;
-
- ret = iknow_register_cmd(ihandle, "show vlan summary", "display vlan flow summary", ifuncb_show_vlan_summary, NULL, 0, NULL);
- assert(0 == ret);
-
- ret = iknow_register_cmd(ihandle, "show vlan id summary", "display vlan flow summary by id", ifuncb_show_vlan_id_summary, NULL, 0, NULL);
- assert(0 == ret);
-}
-
-void packet_io_status_vlan_time_cb(void)
-{
- int i, j;
- packet_io_status_vlan_t *global_vlan_status;
-
- memcpy((void *)&g_io_vlan_last_status, (void *)&g_io_vlan_cur_status, sizeof(packet_io_status_vlan_t)); /* ������һ���ֵ */
- memset((void *)&g_io_vlan_cur_status, 0, sizeof(packet_io_status_vlan_t)); /* ���� */
-
- for(i = 0; i < g_packet_io_thread_num; i++){
- global_vlan_status = (packet_io_status_vlan_t *)(g_packet_io_status_pool[i]->packet_io_status[IO_STATUS_VLAN]);
- g_io_vlan_cur_status.io_base_status.pkt_num += global_vlan_status->io_base_status.pkt_num;
- g_io_vlan_cur_status.io_base_status.pkt_byte += global_vlan_status->io_base_status.pkt_byte;
- for(j = 0; j < VLAN_ID_MAX; j++){
- g_io_vlan_cur_status.vlan_pkt_num[j] += global_vlan_status->vlan_pkt_num[j];
- g_io_vlan_cur_status.vlan_pkt_byte[j] += global_vlan_status->vlan_pkt_byte[j];
- }
- }
-
- g_io_vlan_realtime_status.io_base_status.pkt_num = g_io_vlan_cur_status.io_base_status.pkt_num - g_io_vlan_last_status.io_base_status.pkt_num;
- g_io_vlan_realtime_status.io_base_status.pkt_byte = g_io_vlan_cur_status.io_base_status.pkt_byte - g_io_vlan_last_status.io_base_status.pkt_byte;
-}
-
-void *packet_io_status_vlan_mem_init(void)
-{
- void *vlan_mem;
-
- vlan_mem = malloc(sizeof(packet_io_status_vlan_t));
- memset(vlan_mem, 0, sizeof(packet_io_status_vlan_t));
-
- return vlan_mem;
-}
-
-static inline void packet_io_vlan_status_update(int thread_seq, const struct layer_addr_vlan *addr, int raw_pkt_len)
-{
- packet_io_status_vlan_t *io_vlan_status = (packet_io_status_vlan_t *)(g_packet_io_status_pool[thread_seq]->packet_io_status[IO_STATUS_VLAN]);
-
- io_vlan_status->io_base_status.pkt_num++;
- io_vlan_status->io_base_status.pkt_byte += raw_pkt_len;
-
- io_vlan_status->vlan_pkt_num[addr->vlan_id]++;
- io_vlan_status->vlan_pkt_byte[addr->vlan_id] += raw_pkt_len;
-}
-#else
-int packet_io_status_vlan_init(void)
-{
- return 0;
-}
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "stream_internal.h"
+#include "sendpacket.h"
+#include "stream_manage.h"
+#include "packet_io.h"
+#include "packet_io_internal.h"
+#include <linux/if_ether.h>
+
+#define VLAN_ID_MAX (4096) /* vlan id is 12bit, max is 4096 */
+
+#if DEBUG
+static inline void packet_io_vlan_status_update(int thread_seq, const struct layer_addr_vlan *addr, int raw_pkt_len);
+#endif
+
+static inline void set_vlanid(struct layer_addr_vlan *addr, unsigned short *vlan_tag)
+{
+ addr->vlan_id = ntohs(*vlan_tag) & VLAN_ID_MASK;
+ return;
+}
+
+int vlan_8021q_entry(struct streaminfo_private *pfstream_pr,const void *this_layer_data,int thread_num,
+ unsigned char routedir, const raw_pkt_t *raw_pkt, int offset_to_raw_pkt_hdr)
+{
+ int ret = PASS;
+ struct streamindex tmp_index;
+ struct streamindex *ptmp=&tmp_index;
+ struct streaminfo_private *pstream_pr = &ptmp->stream;
+ struct streaminfo *pstream = &pstream_pr->stream_public;
+ struct layer_addr_vlan addr;
+ u_short ether_type;
+ char *next_layer_hdr = (char *)this_layer_data+ VLAN_TAG_LEN;
+ int next_layer_offset = offset_to_raw_pkt_hdr + VLAN_TAG_LEN;
+
+ if(unlikely(0 == G_SKIP_NOT_IP_LAYER)){
+ memset(ptmp,0,sizeof(struct streamindex));
+ set_vlanid(&addr, (unsigned short *)this_layer_data);
+#if DEBUG
+ packet_io_vlan_status_update(thread_num, &addr, raw_pkt->raw_pkt_len);
+#endif
+ pstream->addr.paddr=&addr;
+ pstream->addr.addrtype = ADDR_TYPE_VLAN;
+ pstream->addr.addrlen = sizeof(struct layer_addr_vlan);
+ pstream_pr->addr_use_as_hash = 1;
+ //ptmp->stream.p_layer_header = this_layer_data;
+ //ptmp->stream.offset_to_raw_pkt_hdr = (char *)this_layer_data - (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->pfather=&pfstream_pr->stream_public;
+ pstream->type=STREAM_TYPE_NON;
+ pstream->routedir=routedir;
+ pstream->threadnum=thread_num;
+ }else{
+ pstream_pr = pfstream_pr; /* 2015-07-03 lijia add, skip this layer */
+ }
+
+ ether_type=*((unsigned short *)((char *)this_layer_data + 2));
+ ether_type = ntohs(ether_type);
+
+ switch(ether_type)
+ {
+ case ETH_P_IP:
+ ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
+ ret=ipv4_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset);
+ break;
+ case ETH_P_IPV6:
+ ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
+ ret=ipv6_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset);
+ break;
+
+ case ETH_P_8021Q:
+ ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
+ ret=vlan_8021q_entry(pstream_pr, next_layer_hdr,thread_num, routedir,raw_pkt, next_layer_offset);
+ break;
+
+ case ETH_P_PPP_SES:
+#if COMPAT_PAPP_FOR_BENCHMARK
+ return PASS;
+#endif
+ ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
+ ret=pppoe_session_entry(pstream_pr,next_layer_hdr,thread_num,routedir,raw_pkt, next_layer_offset);
+ break;
+
+ case ETH_P_MPLS_UC:
+ case ETH_P_MPLS_MC:
+ ((raw_pkt_t *)raw_pkt)->offset_to_raw_pkt_hdr = next_layer_offset;
+ ret = mpls_uc_entry(pstream_pr, (const void *)next_layer_hdr, thread_num, routedir, raw_pkt, next_layer_offset);
+ break;
+
+ default:
+ /* unknown protocol */
+ g_SysInputInfo[thread_num][PKT_UNKNOWN]++;
+ g_SysInputInfo[thread_num][PKT_UNKNOWN_LEN] += raw_pkt->raw_pkt_len;
+
+ sapp_runtime_log(20, "VLAN unknown protocol: 0x%x\n", ether_type);
+
+ if(NET_CONN_SERIAL_GDEV == g_topology_mode){
+ /* GDEVģʽ��, ʲôʱ�򶼲�Ӧ�ðѲ���ʶ�İ���ת����ȥ, ���߷��ְ�SPT������Э����ע��ȥ, ����������� */
+ ret = DROP;
+ }else{
+ ret = PASS;
+ }
+ break;
+ }
+
+ return ret;
+}
+
+#if DEBUG
+#include "iknow.h"
+
+extern int g_packet_io_thread_num;
+extern packet_io_status_t *g_packet_io_status_pool[MAX_THREAD_NUM];
+
+/*
+ sysinfo֮ǰ�Ǽ򵥶�ά����, ���ܱ�ʾ���̡߳���Э�顢��Э��ľ������.
+
+ �µļܹ���, ÿ��Э�������ṹ, ��packet_io_status_base_t��������չ,
+ ��֮ǰ��sysinfo�ļ򵥶�ά���鲻ͬ,
+ �½ṹÿ��Э��洢�����Ͳ�ͬ, �ṹҲ��ͬ,
+ �߼�����, �ڴ�ʹ�����Ż�.
+*/
+typedef struct{
+ packet_io_status_base_t io_base_status; /* VLAN���ܼ��� */
+ unsigned long long vlan_pkt_num[VLAN_ID_MAX]; /* ÿ��VLAN�İ��� */
+ unsigned long long vlan_pkt_byte[VLAN_ID_MAX]; /* ÿ��VLAN���ֽ��� */
+}packet_io_status_vlan_t;
+
+/* ����: ��һ��:1000B, ��ǰ:5000B, �ɼ�������һ���ʵʱ����:4000B/s */
+static volatile packet_io_status_vlan_t g_io_vlan_last_status, g_io_vlan_cur_status, g_io_vlan_realtime_status;
+
+static long ifuncb_show_vlan_id_summary(iknow_handle ihandle, iknow_conn iconn, const void *cb_fun_arg,const char *cmd_args)
+{
+ int i;
+ /* ȫ��vlan-id�ܰ���, ���ֽ��� */
+ iprintf(ihandle, iconn, "vlan id summary:\n %7s %9s %10s\n", "VLAN-ID", "Total-pkt", "Total-byte");
+ for(i = 0; i < VLAN_ID_MAX; i++){
+ if(g_io_vlan_cur_status.vlan_pkt_num[i] > 0){
+ iprintf(ihandle, iconn, "%7d %9llu %10llu\n", i, g_io_vlan_cur_status.vlan_pkt_num[i], g_io_vlan_cur_status.vlan_pkt_byte[i] );
+ }
+ }
+
+ return 0;
+}
+
+static long ifuncb_show_vlan_summary(iknow_handle ihandle, iknow_conn iconn, const void *cb_fun_arg, const char *cmd_args)
+{
+ /* ȫ���ܰ���, ���ֽ��� */
+ iprintf(ihandle, iconn,"NOTE: unit of byte for total is 'byte', for realtime is 'bps, bit per second'!\n");
+ iprintf(ihandle, iconn, "%8s %8s %12s\n", " ", "packet", "byte");
+ iprintf(ihandle, iconn, "%8s %8llu %12llu\n%8s %8llu %12llu\n",
+ "total", g_io_vlan_cur_status.io_base_status.pkt_num, g_io_vlan_cur_status.io_base_status.pkt_byte,
+ "realtime", g_io_vlan_realtime_status.io_base_status.pkt_num, g_io_vlan_realtime_status.io_base_status.pkt_byte*8);
+
+ return 0;
+}
+
+void iknow_register_vlan_cb(void *ihandle)
+{
+ int ret;
+
+ ret = iknow_register_cmd(ihandle, "show vlan summary", "display vlan flow summary", ifuncb_show_vlan_summary, NULL, 0, NULL);
+// assert(0 == ret);
+
+ ret = iknow_register_cmd(ihandle, "show vlan id summary", "display vlan flow summary by id", ifuncb_show_vlan_id_summary, NULL, 0, NULL);
+// assert(0 == ret);
+}
+
+void packet_io_status_vlan_time_cb(void)
+{
+ int i, j;
+ packet_io_status_vlan_t *global_vlan_status;
+
+ memcpy((void *)&g_io_vlan_last_status, (void *)&g_io_vlan_cur_status, sizeof(packet_io_status_vlan_t)); /* ������һ���ֵ */
+ memset((void *)&g_io_vlan_cur_status, 0, sizeof(packet_io_status_vlan_t)); /* ���� */
+
+ for(i = 0; i < g_packet_io_thread_num; i++){
+ global_vlan_status = (packet_io_status_vlan_t *)(g_packet_io_status_pool[i]->packet_io_status[IO_STATUS_VLAN]);
+ g_io_vlan_cur_status.io_base_status.pkt_num += global_vlan_status->io_base_status.pkt_num;
+ g_io_vlan_cur_status.io_base_status.pkt_byte += global_vlan_status->io_base_status.pkt_byte;
+ for(j = 0; j < VLAN_ID_MAX; j++){
+ g_io_vlan_cur_status.vlan_pkt_num[j] += global_vlan_status->vlan_pkt_num[j];
+ g_io_vlan_cur_status.vlan_pkt_byte[j] += global_vlan_status->vlan_pkt_byte[j];
+ }
+ }
+
+ g_io_vlan_realtime_status.io_base_status.pkt_num = g_io_vlan_cur_status.io_base_status.pkt_num - g_io_vlan_last_status.io_base_status.pkt_num;
+ g_io_vlan_realtime_status.io_base_status.pkt_byte = g_io_vlan_cur_status.io_base_status.pkt_byte - g_io_vlan_last_status.io_base_status.pkt_byte;
+}
+
+void *packet_io_status_vlan_mem_init(void)
+{
+ void *vlan_mem;
+
+ vlan_mem = malloc(sizeof(packet_io_status_vlan_t));
+ memset(vlan_mem, 0, sizeof(packet_io_status_vlan_t));
+
+ return vlan_mem;
+}
+
+static inline void packet_io_vlan_status_update(int thread_seq, const struct layer_addr_vlan *addr, int raw_pkt_len)
+{
+ packet_io_status_vlan_t *io_vlan_status = (packet_io_status_vlan_t *)(g_packet_io_status_pool[thread_seq]->packet_io_status[IO_STATUS_VLAN]);
+
+ io_vlan_status->io_base_status.pkt_num++;
+ io_vlan_status->io_base_status.pkt_byte += raw_pkt_len;
+
+ io_vlan_status->vlan_pkt_num[addr->vlan_id]++;
+ io_vlan_status->vlan_pkt_byte[addr->vlan_id] += raw_pkt_len;
+}
+#else
+int packet_io_status_vlan_init(void)
+{
+ return 0;
+}
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/dealpkt/stream_manage.c b/dealpkt/stream_manage.c
index b95a299..ac8c3c6 100644
--- a/dealpkt/stream_manage.c
+++ b/dealpkt/stream_manage.c
@@ -2541,9 +2541,9 @@ void iknow_register_stream_hash_cb(void *ihandle)
int ret;
ret = iknow_register_cmd(ihandle, "show stream summary", "display stream hash summary", ifuncb_show_stream_hash_summary, NULL, 0, NULL);
- assert(0 == ret);
+ //assert(0 == ret);
ret = iknow_register_cmd(ihandle, "show stream detail", "display stream hash detail", ifuncb_show_stream_hash_detail, NULL, 0, NULL);
- assert(0 == ret);
+ //assert(0 == ret);
}
void packet_io_status_stream_hash_update(int thread_seq, unsigned long hash_list_num)
diff --git a/entry/CMakeLists.txt b/entry/CMakeLists.txt
index ed8881a..8cf03aa 100644
--- a/entry/CMakeLists.txt
+++ b/entry/CMakeLists.txt
@@ -29,21 +29,21 @@ set(SAPP_MODULES iknow timestamp_record md5 symbol_check MESA_sleep MESA_socket_
target_link_libraries(sapp -Wl,--whole-archive ${SAPP_MODULES} -Wl,--no-whole-archive ${SAPP_DEPEND_DYN_LIB})
-if(CAPTURE_MODE MATCHES "PAG")
- target_link_libraries(sapp pag)
-endif()
-
-if(CAPTURE_MODE MATCHES "PPF")
- target_link_libraries(psapp ppf)
-endif()
-
-if(CAPTURE_MODE MATCHES "PFRING")
- target_link_libraries(sapp pfring)
-endif()
+#if(CAPTURE_MODE MATCHES "PAG")
+# target_link_libraries(sapp pag)
+#endif()
-if(CAPTURE_MODE MATCHES "DPDK")
- target_link_libraries(sapp nl2fwd)
-endif()
+#if(CAPTURE_MODE MATCHES "PPF")
+# target_link_libraries(psapp ppf)
+#endif()
+#
+#if(CAPTURE_MODE MATCHES "PFRING")
+# target_link_libraries(sapp pfring)
+#endif()
+#
+#if(CAPTURE_MODE MATCHES "DPDK")
+# target_link_libraries(sapp nl2fwd)
+#endif()
# Target Install
#install(TARGETS sapp DESTINATION ${CMAKE_SOURCE_DIR}/run/)
diff --git a/entry/sapp_init.c b/entry/sapp_init.c
index 0b285c8..2efc9e1 100644
--- a/entry/sapp_init.c
+++ b/entry/sapp_init.c
@@ -139,7 +139,7 @@ int MESA_platform_init(int argc, char *argv[])
exit(1);
}
- if(MESA_load_profile_int_def("conf/main.conf", "Module", "threadnum", &threadnum, 1) < 0){
+ if(MESA_load_profile_int_def("conf/main.conf", "Module", "threadnum", &threadnum, 1) < 0 || threadnum <= 0){
printf("read conf 'threadnum' error!\n");
exit(1);
}
@@ -340,7 +340,7 @@ int MESA_platform_init(int argc, char *argv[])
init_stream_manage(threadnum);
#if DEBUG
- MESA_load_profile_int_def("conf/main.conf", "Module", "iknow_switch", &int_tmp, 1);
+ MESA_load_profile_int_def("conf/main.conf", "ShowStatInfo", "iknow_switch", &int_tmp, 0);
if(int_tmp != 0){
iknow_info_init();
}
@@ -348,6 +348,8 @@ int MESA_platform_init(int argc, char *argv[])
timestamp_record_init();
#endif
+ sapp_assistant_init();
+
MESA_load_profile_int_def("conf/main.conf","Module", "load_plug_switch", &load_plug_sw, 1);
if(load_plug_sw){
plugctrl_proc();
@@ -411,8 +413,6 @@ int MESA_platform_init(int argc, char *argv[])
MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"Module", (char *)"create_mpls_anyway", &sapp_global_single.create_mpls_anyway, 0);
MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"Module", (char *)"send_fake_pkt_mode", &sapp_global_single.send_fake_pkt_mode, 0);
MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"Module", (char *)"send_fake_pkt_gdev_sport", &sapp_global_single.send_fake_pkt_gdev_sport, 15);
-
- sapp_assistant_init();
MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"Module", (char *)"send_tcp_offload", &sapp_global_single.cfg_send_tcp_offload_sw, 0);
MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"Module", (char *)"treat_vlan_as_mac_in_mac", &sapp_global_single.treat_vlan_as_mac_in_mac_sw, 0);
diff --git a/include/stream_internal.h b/include/stream_internal.h
index de383e8..049ef2e 100644
--- a/include/stream_internal.h
+++ b/include/stream_internal.h
@@ -287,10 +287,13 @@ struct sapp_global_single_t{
const char *fs2_server_ip;
unsigned short fs2_server_port_host;
short __pad1;
- int fs2_filed_id_array[COUNTER_NUM];
+ int fs2_sysinfo_id_array[COUNTER_NUM];
int fs2_latency_id_array[COUNTER_NUM];
+ int fs2_plug_init_time_id_array[COUNTER_NUM];
+ int fs2_plug_lantency_id_array[COUNTER_NUM][MAX_THREAD_NUM];
+
int send_fake_pkt_mode; /* 2018-10-26 lijia add, for PanGu, ����ȱ��FD·��, ����ô���GDEV����rst��, DNS-fake����,mode 0�� Э��ջ���㷢���� 1��Э��ջ���㷢����3��gdevע�뷢������ģʽ��send_fake_pkt_gdev_sport��Ч */
int send_fake_pkt_gdev_sport; /* 2018-10-26 lijia add, for PanGu, ����ѡ��vxlanԴ�˿� */
diff --git a/include/sysinfo.h b/include/sysinfo.h
index 5aa9718..3f6b401 100644
--- a/include/sysinfo.h
+++ b/include/sysinfo.h
@@ -1,147 +1,150 @@
-#ifndef __SYSINFO_H__
-#define __SYSINFO_H__
-
-
-#ifndef MAX_THREAD_NUM
-#define MAX_THREAD_NUM 128
-#endif
-
-#define SYS_COUNTER_ON
-#define COUNTER_NUM (4096) /*newly added ---LiLei*/
-
-
-#define COUNTER_PKT 240
-#define COUNTER_PKTLEN 241
-#define COUNTER_DROP_PKT 242
-#define COUNTER_DROP_PKTLEN 243
-#define COUNTER_DROPLINK 244 //2??����?��e??1?��?��?����?��
-#define COUNTER_CLOSELINK 245 //?��1?��?��e?a��|��?2?D-������?��?��?D-������?��??����Y2?D����a��|������??��??��|����1y3��?D3?�䨪��??��?D��?����?��
-
-
-//---pkt info
-
-#define PKTINFO_BASE 0
-#define PKT_ETHERNET 0
-#define PKT_IP_FRAG 1
-#define PKT_IP 2
-#define PKT_TCP 3
-#define PKT_UDP 4
-#define PKT_IPLEN 5
-#define PKT_TCPLEN 6
-#define PKT_UDPLEN 8
-#define PKT_TCP_DROP 11 //2?D����atcp2?��|������?�㨹??��y
-#define PKT_TCP_DROPLEN 12 //2?D����atcp2?��|������?�㨹3��?��
-#define PKT_TCP_UNORDER 13 //?��D���㨹��???��y
-#define PKT_TCP_APP 14
-#define PKT_TCP_APP_LEN 15
-#define HTTP_CON_NOGZ 16
-#define HTTP_CON_GZ 17
-#define HTTP_CON_NO_GZAV 18
-#define HTTP_CON_GZAV 19
-
-//---link info
-#define LINKINFO_BASE 20
-#define LINK_TATAL 20
-#define LINK_TATAL_DROP 21
-#define LINK_APPTATAL 22
-#define LINK_DROP_NOUSE 23 //2??����?��e??1?��?��?����?��
-#ifndef PLATFORM_NSDPF_PAPP /* 2013-02-25 lijia modify, LINK_CLOSE��?stream_manage.h?D3?��?��????? */
-#define LINK_CLOSE 24 //?��1?��?��e?a��|��?2?D-������?��?��?D-������?��??����Y2?D����a��|������??��??��|����1y3��?D3?�䨪��??��?D��?����?��
-#else
-#define NIDS_LINK_CLOSE 24
-#endif
-#define LINK_SINGLE_C2S 25 // �̣�?������?��
-#define LINK_SINGLE_S2C 26 // �̣�?������?��
-#define LINK_DOUBLE 27 //
-#define LINK_KILL 28 //
-
-/* 2014-12-02 lijia add */
-#define PKT_IPV6 31
-#define PKT_IPV6LEN 32
-#define PKT_ETHERNET_LEN 33
-
-#define SYS_TCP_LINK_SYN (34)
-#define SYS_TCP_LINK_DATA (35)
-#define SYS_TCP_LINK_NOUSE (36)
-#define SYS_TCP_LINK_NEW (37)
-#define SYS_TCP_LINK_DEL (38)
-#define SYS_TCP_LINK_RESET (39) /* tcp???a����??��?��y */
-
-#define SYS_UDP_LINK_ONE (40)
-#define SYS_UDP_LINK_TWO (41)
-#define SYS_UDP_LINK_MORE (42)
-#define SYS_UDP_LINK_NEW (43)
-#define SYS_UDP_LINK_DEL (44)
-#define SYS_UDP_LINK_RESET (45) /* udp???a����??��?��y */
-
-#define SYS_HASH_LIST_MAX (46)
-
-/* 2014-12-02 lijia add */
-#define TCPV4_LINK_TOTAL (47)
-#define TCPV4_LINK_NEW_CREATE (48)
-#define TCPV4_LINK_CLOSE (49)
-#define TCPV6_LINK_TOTAL (50)
-#define TCPV6_LINK_NEW_CREATE (51)
-#define TCPV6_LINK_CLOSE (52)
-
-#define UDPV4_LINK_TOTAL (53)
-#define UDPV4_LINK_NEW_CREATE (54)
-#define UDPV4_LINK_CLOSE (55)
-#define UDPV6_LINK_TOTAL (56)
-#define UDPV6_LINK_NEW_CREATE (57)
-#define UDPV6_LINK_CLOSE (58)
-
-#define TUNNEL_6OVER4 (59)
-
-
-#define TUNNEL_6OVER4_LEN (61)
-#define TUNNEL_4OVER6 (62)
-#define TUNNEL_4OVER6_LEN (63)
-#define TUNNEL_TEREDO (64)
-#define TUNNEL_TEREDO_LEN (65)
-#define TUNNEL_IP_IN_IP (66)
-#define TUNNEL_GTP (67)
-
-#define SEND_IP_RAW_PKT (70) /* ����MESA_sendpacket_iplayer()���͹���õ�IP������ */
-#define SEND_IP_RAW_PKT_LEN (71)
-#define SEND_IP_PKT (72)
-#define SEND_IP_PKT_LEN (73)
-#define SEND_TCP_PKT (74) /* MESA_fakepacket_send_tcp()����TCP���ݰ� */
-#define SEND_TCP_PKT_LEN (75)
-#define SEND_TCP_RST (76)
-#define SEND_TCP_RST_LEN (77)
-#define SEND_TCP_SYN_ACK (78)
-#define SEND_TCP_SYN_ACK_LEN (79)
-#define SEND_UDP_PKT (80) /* MESA_fakepacket_send_udp()����UDP���ݰ� */
-#define SEND_UDP_PKT_LEN (81)
-
-#define SEND_PKT_ERR (82)
-#define SEND_PKT_ERR_LEN (83) /* sendto error */
-
-/* 2014-12-02 lijia add */
-#define PKT_UNKNOWN (98)
-#define PKT_UNKNOWN_LEN (99)
-
-
-//group info
-
-#define PKT_APP_BASE 1000
-//--app count (30)
-#define LINK_APP_BASE 1500
-#define IP_FRAG_GROUP_BASE 2000
-#define TCP_UNORDER_GROUP_BASE 3000
-
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-extern volatile unsigned int g_aiSysCounter[COUNTER_NUM]; /*newly modified ---LiLei*/
-
-extern volatile unsigned long long g_SysInputInfo[MAX_THREAD_NUM][COUNTER_NUM];
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+#ifndef __SYSINFO_H__
+#define __SYSINFO_H__
+
+
+#ifndef MAX_THREAD_NUM
+#define MAX_THREAD_NUM 128
+#endif
+
+#define SYS_COUNTER_ON
+#define COUNTER_NUM (4096) /*newly added ---LiLei*/
+
+
+#define COUNTER_PKT 240
+#define COUNTER_PKTLEN 241
+#define COUNTER_DROP_PKT 242
+#define COUNTER_DROP_PKTLEN 243
+#define COUNTER_DROPLINK 244 //2??����?��e??1?��?��?����?��
+#define COUNTER_CLOSELINK 245 //?��1?��?��e?a��|��?2?D-������?��?��?D-������?��??����Y2?D����a��|������??��??��|����1y3��?D3?�䨪��??��?D��?����?��
+
+
+//---pkt info
+
+#define PKTINFO_BASE 0
+#define PKT_ETHERNET 0
+#define PKT_IP_FRAG 1
+#define PKT_IP 2
+#define PKT_TCP 3
+#define PKT_UDP 4
+#define PKT_IPLEN 5
+#define PKT_TCPLEN 6
+#define PKT_UDPLEN 8
+#define PKT_TCP_DROP 11 //2?D����atcp2?��|������?�㨹??��y
+#define PKT_TCP_DROPLEN 12 //2?D����atcp2?��|������?�㨹3��?��
+#define PKT_TCP_UNORDER 13 //?��D���㨹��???��y
+#define PKT_TCP_APP 14
+#define PKT_TCP_APP_LEN 15
+#define HTTP_CON_NOGZ 16
+#define HTTP_CON_GZ 17
+#define HTTP_CON_NO_GZAV 18
+#define HTTP_CON_GZAV 19
+
+//---link info
+#define LINKINFO_BASE 20
+#define LINK_TATAL 20
+#define LINK_TATAL_DROP 21
+#define LINK_APPTATAL 22
+#define LINK_DROP_NOUSE 23 //2??����?��e??1?��?��?����?��
+#ifndef PLATFORM_NSDPF_PAPP /* 2013-02-25 lijia modify, LINK_CLOSE��?stream_manage.h?D3?��?��????? */
+#define LINK_CLOSE 24 //?��1?��?��e?a��|��?2?D-������?��?��?D-������?��??����Y2?D����a��|������??��??��|����1y3��?D3?�䨪��??��?D��?����?��
+#else
+#define NIDS_LINK_CLOSE 24
+#endif
+#define LINK_SINGLE_C2S 25 // �̣�?������?��
+#define LINK_SINGLE_S2C 26 // �̣�?������?��
+#define LINK_DOUBLE 27 //
+#define LINK_KILL 28 //
+
+/* 2014-12-02 lijia add */
+#define PKT_IPV6 31
+#define PKT_IPV6LEN 32
+#define PKT_ETHERNET_LEN 33
+
+#define SYS_TCP_LINK_SYN (34)
+#define SYS_TCP_LINK_DATA (35)
+#define SYS_TCP_LINK_NOUSE (36)
+#define SYS_TCP_LINK_NEW (37)
+#define SYS_TCP_LINK_DEL (38)
+#define SYS_TCP_LINK_RESET (39) /* tcp???a����??��?��y */
+
+#define SYS_UDP_LINK_ONE (40)
+#define SYS_UDP_LINK_TWO (41)
+#define SYS_UDP_LINK_MORE (42)
+#define SYS_UDP_LINK_NEW (43)
+#define SYS_UDP_LINK_DEL (44)
+#define SYS_UDP_LINK_RESET (45) /* udp???a����??��?��y */
+
+#define SYS_HASH_LIST_MAX (46)
+
+/* 2014-12-02 lijia add */
+#define TCPV4_LINK_TOTAL (47)
+#define TCPV4_LINK_NEW_CREATE (48)
+#define TCPV4_LINK_CLOSE (49)
+#define TCPV6_LINK_TOTAL (50)
+#define TCPV6_LINK_NEW_CREATE (51)
+#define TCPV6_LINK_CLOSE (52)
+
+#define UDPV4_LINK_TOTAL (53)
+#define UDPV4_LINK_NEW_CREATE (54)
+#define UDPV4_LINK_CLOSE (55)
+#define UDPV6_LINK_TOTAL (56)
+#define UDPV6_LINK_NEW_CREATE (57)
+#define UDPV6_LINK_CLOSE (58)
+
+#define TUNNEL_6OVER4 (59)
+
+
+#define TUNNEL_6OVER4_LEN (61)
+#define TUNNEL_4OVER6 (62)
+#define TUNNEL_4OVER6_LEN (63)
+#define TUNNEL_TEREDO (64)
+#define TUNNEL_TEREDO_LEN (65)
+#define TUNNEL_IP_IN_IP (66)
+#define TUNNEL_GTP (67)
+
+#define SEND_IP_RAW_PKT (70) /* ����MESA_sendpacket_iplayer()���͹���õ�IP������ */
+#define SEND_IP_RAW_PKT_LEN (71)
+#define SEND_IP_PKT (72)
+#define SEND_IP_PKT_LEN (73)
+#define SEND_TCP_PKT (74) /* MESA_fakepacket_send_tcp()����TCP���ݰ� */
+#define SEND_TCP_PKT_LEN (75)
+#define SEND_TCP_RST (76)
+#define SEND_TCP_RST_LEN (77)
+#define SEND_TCP_SYN_ACK (78)
+#define SEND_TCP_SYN_ACK_LEN (79)
+#define SEND_UDP_PKT (80) /* MESA_fakepacket_send_udp()����UDP���ݰ� */
+#define SEND_UDP_PKT_LEN (81)
+
+#define SEND_PKT_ERR (82)
+#define SEND_PKT_ERR_LEN (83) /* sendto error */
+
+/* 2014-12-02 lijia add */
+#define PKT_UNKNOWN (98)
+#define PKT_UNKNOWN_LEN (99)
+
+#define TCP_LINK_DISPOSABLE (100)
+#define UDP_LINK_DISPOSABLE (101)
+#define STREAM_DISPOSABLE (102)
+
+//group info
+
+#define PKT_APP_BASE 1000
+//--app count (30)
+#define LINK_APP_BASE 1500
+#define IP_FRAG_GROUP_BASE 2000
+#define TCP_UNORDER_GROUP_BASE 3000
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern volatile unsigned int g_aiSysCounter[COUNTER_NUM]; /*newly modified ---LiLei*/
+
+extern volatile unsigned long long g_SysInputInfo[MAX_THREAD_NUM][COUNTER_NUM];
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/inner_plug/CMakeLists.txt b/inner_plug/CMakeLists.txt
index 44ca655..94cc36a 100644
--- a/inner_plug/CMakeLists.txt
+++ b/inner_plug/CMakeLists.txt
@@ -28,7 +28,7 @@ set_target_properties(isakmp_protocol_plug PROPERTIES PREFIX "")
add_library(g_device_plug SHARED g_device_plug.c)
set_target_properties(g_device_plug PROPERTIES PREFIX "")
-if(ENABLE_STATIC_LINK)
+if(STATIC_LINK)
add_library(sapp_assistant STATIC sapp_assistant.cpp)
add_library(gdev_assistant STATIC gdev_assistant.c)
else()
diff --git a/inner_plug/sapp_assistant.cpp b/inner_plug/sapp_assistant.cpp
index 51946c9..9e42577 100644
--- a/inner_plug/sapp_assistant.cpp
+++ b/inner_plug/sapp_assistant.cpp
@@ -328,9 +328,6 @@ static int sapp_fs2_init(void)
MESA_load_profile_int_def("conf/main.conf", "ShowStatInfo", "FS_send_histogram", &send_historgram, 0);
- FS_set_para(sapp_global_single.fs2_handle, NOT_SEND_METRIC_TO_SERVER, &send_historgram, sizeof(int));
-
-
FS_set_para(sapp_global_single.fs2_handle, OUTPUT_DEVICE, "fs2_sysinfo.log", strlen("fs2_sysinfo.log")+1);
FS_set_para(sapp_global_single.fs2_handle, APP_NAME, fs_name, strlen(fs_name)+1);
@@ -339,36 +336,36 @@ static int sapp_fs2_init(void)
FS_set_para(sapp_global_single.fs2_handle, STATS_SERVER_PORT, &sapp_global_single.fs2_server_port_host, sizeof(short));
- sapp_global_single.fs2_filed_id_array[PKT_ETHERNET] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ethernet_pps");
- sapp_global_single.fs2_filed_id_array[PKT_ETHERNET_LEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ethernet_bps");
+ sapp_global_single.fs2_sysinfo_id_array[PKT_ETHERNET] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ethernet_pps");
+ sapp_global_single.fs2_sysinfo_id_array[PKT_ETHERNET_LEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ethernet_bps");
- sapp_global_single.fs2_filed_id_array[PKT_IP] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv4_pps");
- sapp_global_single.fs2_filed_id_array[PKT_IPLEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv4_bps");
+ sapp_global_single.fs2_sysinfo_id_array[PKT_IP] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv4_pps");
+ sapp_global_single.fs2_sysinfo_id_array[PKT_IPLEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv4_bps");
- sapp_global_single.fs2_filed_id_array[PKT_IPV6] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv6_pps");
- sapp_global_single.fs2_filed_id_array[PKT_IPV6LEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv6_bps");
+ sapp_global_single.fs2_sysinfo_id_array[PKT_IPV6] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv6_pps");
+ sapp_global_single.fs2_sysinfo_id_array[PKT_IPV6LEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "IPv6_bps");
- sapp_global_single.fs2_filed_id_array[PKT_TCP] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_pps");
- sapp_global_single.fs2_filed_id_array[PKT_TCPLEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_bps");
+ sapp_global_single.fs2_sysinfo_id_array[PKT_TCP] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_pps");
+ sapp_global_single.fs2_sysinfo_id_array[PKT_TCPLEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_bps");
- sapp_global_single.fs2_filed_id_array[PKT_UDP] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "UDP_pps");
- sapp_global_single.fs2_filed_id_array[PKT_UDPLEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "UDP_bps");
+ sapp_global_single.fs2_sysinfo_id_array[PKT_UDP] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "UDP_pps");
+ sapp_global_single.fs2_sysinfo_id_array[PKT_UDPLEN] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "UDP_bps");
- sapp_global_single.fs2_filed_id_array[SYS_TCP_LINK_NEW] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_NEW");
- sapp_global_single.fs2_filed_id_array[SYS_TCP_LINK_DEL] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_DEL");
- sapp_global_single.fs2_filed_id_array[SYS_TCP_LINK_DATA] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_CONCURRENT");
+ sapp_global_single.fs2_sysinfo_id_array[SYS_TCP_LINK_NEW] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_NEW");
+ sapp_global_single.fs2_sysinfo_id_array[SYS_TCP_LINK_DEL] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_DEL");
+ sapp_global_single.fs2_sysinfo_id_array[SYS_TCP_LINK_DATA] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_CONCURRENT");
- sapp_global_single.fs2_filed_id_array[LINK_DOUBLE] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD,
- FS_CALC_CURRENT, "TCP_LINK_DOUBLE");
- sapp_global_single.fs2_filed_id_array[LINK_SINGLE_C2S] = FS_register(sapp_global_single.fs2_handle,
- FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_C2S");
- sapp_global_single.fs2_filed_id_array[LINK_SINGLE_S2C] = FS_register(sapp_global_single.fs2_handle,
- FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_S2C");
+ sapp_global_single.fs2_sysinfo_id_array[LINK_DOUBLE] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD,
+ FS_CALC_CURRENT, "TCP_LINK_DOUBLE");
+ sapp_global_single.fs2_sysinfo_id_array[LINK_SINGLE_C2S] = FS_register(sapp_global_single.fs2_handle,
+ FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_C2S");
+ sapp_global_single.fs2_sysinfo_id_array[LINK_SINGLE_S2C] = FS_register(sapp_global_single.fs2_handle,
+ FS_STYLE_FIELD, FS_CALC_CURRENT, "TCP_LINK_S2C");
- sapp_global_single.fs2_filed_id_array[SEND_TCP_RST] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "SEND_TCP_RST");
- sapp_global_single.fs2_filed_id_array[SEND_TCP_SYN_ACK] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "SEND_TCP_S/A");
- sapp_global_single.fs2_filed_id_array[SEND_UDP_PKT] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "SEND_UDP");
+ sapp_global_single.fs2_sysinfo_id_array[SEND_TCP_RST] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "SEND_TCP_RST");
+ sapp_global_single.fs2_sysinfo_id_array[SEND_TCP_SYN_ACK] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "SEND_TCP_S/A");
+ sapp_global_single.fs2_sysinfo_id_array[SEND_UDP_PKT] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "SEND_UDP");
if(unlikely(g_timestamp_record_sw))
{
for(int i = 0; i < g_packet_io_thread_num; i++)
@@ -443,16 +440,62 @@ void sapp_statsd_add_para(const char *key, unsigned long long value)
}
#endif
+void sapp_fs2_register_plug_id(int plug_id, const char *plug_name)
+{
+ if(sapp_global_single.fs2_handle != NULL)
+ {
+ char status_name[NAME_MAX];
+ sprintf(status_name, "%s(us)", plug_name);
+ sapp_global_single.fs2_plug_init_time_id_array[plug_id] = FS_register(sapp_global_single.fs2_handle, FS_STYLE_STATUS, FS_CALC_CURRENT, status_name);
+ FS_set_para(sapp_global_single.fs2_handle, NOT_SEND_METRIC_TO_SERVER, &sapp_global_single
+ .fs2_plug_init_time_id_array[plug_id], sizeof(int));
+ if(unlikely(g_timestamp_record_sw))
+ {
+ for(int i = 0; i < g_packet_io_thread_num; i++)
+ {
+ char histogram_name[NAME_MAX];
+ sprintf(histogram_name, "%s_%d(ns)", plug_name, i);
+ sapp_global_single.fs2_plug_lantency_id_array[plug_id][i] = FS_register_histogram(sapp_global_single.fs2_handle, //Field Stat���
+ FS_CALC_SPEED, //����ۼ�ֵ��˲ʱֵ
+ histogram_name, //ͳ�������ƣ��ַ���
+ 1, //��׷�ٵ���Сֵ
+ 1000000, //��׷�ٵ����ֵ
+ 2); //���ȣ���С�����λ����Χ1~4
+ FS_set_para(sapp_global_single.fs2_handle, NOT_SEND_METRIC_TO_SERVER, &sapp_global_single
+ .fs2_plug_lantency_id_array[plug_id][i], sizeof(int));
+ }
+ }
+ }
+}
+
+void sapp_fs2_set_plug_init_time(int plug_id, long long time_us)
+{
+ if(sapp_global_single.fs2_handle != NULL)
+ {
+ FS_operate(sapp_global_single.fs2_handle, sapp_global_single.fs2_plug_init_time_id_array[plug_id], 0, FS_OP_SET, (long long)time_us);
+ }
+}
+
+void sapp_fs2_set_plug_lantency(int plug_id, int thread_seq, long long time_cost)
+{
+ if(likely(sapp_global_single.fs2_handle != NULL) && unlikely(g_timestamp_record_sw))
+ {
+ FS_operate(sapp_global_single.fs2_handle, sapp_global_single.fs2_plug_lantency_id_array[plug_id][thread_seq], 0, FS_OP_SET, time_cost);
+ }
+}
+
void sapp_fs2_update(int field_index, unsigned long long value)
{
- if(sapp_global_single.fs2_handle != NULL){
- FS_operate(sapp_global_single.fs2_handle, sapp_global_single.fs2_filed_id_array[field_index], 0, FS_OP_SET, (long long)value);
+ if(sapp_global_single.fs2_handle != NULL)
+ {
+ FS_operate(sapp_global_single.fs2_handle, sapp_global_single.fs2_sysinfo_id_array[field_index], 0, FS_OP_SET, (long long)value);
}
}
void sapp_fs2_set_latency(int thead_seq, long long time_cost)
{
- if(sapp_global_single.fs2_handle != NULL){
+ if(sapp_global_single.fs2_handle != NULL)
+ {
FS_operate(sapp_global_single.fs2_handle, sapp_global_single.fs2_latency_id_array[thead_seq], 0, FS_OP_SET, time_cost);
}
}
diff --git a/packet_io/packet_io_marsio.c b/packet_io/packet_io_marsio.c
index 7e132d7..07aa157 100644
--- a/packet_io/packet_io_marsio.c
+++ b/packet_io/packet_io_marsio.c
@@ -296,26 +296,6 @@ int dl_io_init(int argc, char *argv[])
marsio4_burst_process_pkt_num = MARSIO_BURST_PKT_MAX - 1;
}
- /* TODO, ֧�ֲ�����COREID����, ��1,2,3,5,9 */
- MESA_load_profile_string_def((char *)"conf/main.conf", (char *)"Module", (char *)"cpu_bind_core_mask", bind_mask_string, 128, "");
- if(bind_mask_string[0] == '\0'){
- marsio4_thread_bind_mask = 0;
- printf("\033[33m[Warning]In marsio mode, not set main.conf->cpu_bind_core_mask value, maybe cause CPU preemption!\033[0m\n");
- sleep(1);
- }else if(strncmp("0x", bind_mask_string, 2) == 0){
- marsio4_thread_bind_mask = strtoul(bind_mask_string, NULL, 16);
- if(calc_integer_bit_num(marsio4_thread_bind_mask) != g_marsio4_work_thread_num){
- printf("\033[41m[Error]main.conf->cpu_bind_core_mask value is not match main.conf->threadnum!\033[0m\n");
- printf("\033[41m main.conf->cpu_bind_core_mask bit numer must match main.conf->threadnum, \033[0m\n");
- printf("\033[41m for example, threadnum=8, core_mask shoule be 0xFF, 0xFF0, 0xFF00, etc.\033[0m\n");
- printf("\033[41m for example, threadnum=16, core_mask shoule be 0xFFFF, 0xFFFF0, 0xFFFF00, etc.\033[0m\n");
- return -1;
- }
- }else{
- printf("\033[41m[Error]main.conf->cpu_bind_core_mask value incorrect!\033[0m\n");
- return -1;
- }
-
mr4_instance = marsio_create();
if(NULL == mr4_instance) {
fprintf(stderr,"%s\n","marsio_create error!\n");
@@ -338,35 +318,78 @@ int dl_io_init(int argc, char *argv[])
g_mario4_io_handle = (marsio4_io_handle *)calloc(1, sizeof(marsio4_io_handle) * g_marsio4_work_thread_num);
marsio_option_set(mr4_instance, MARSIO_OPT_THREAD_NUM, &g_marsio4_work_thread_num, sizeof(int));
-
- MESA_load_profile_string_def((char *)"conf/main.conf", (char *)"Module", (char *)"cpu_bind_core_mask", bind_mask_string, 128, "$");
- if(bind_mask_string[0] == '$'){
- marsio4_thread_bind_mask = 0;
- printf("\033[33m[Warning]In marsio mode, not set main.conf->cpu_bind_core_mask value, maybe cause CPU preemption!\033[0m\n");
- sleep(1);
- }else if(strncmp("0x", bind_mask_string, 2) == 0){
- marsio4_thread_bind_mask = strtoul(bind_mask_string, NULL, 16);
- if(calc_integer_bit_num(marsio4_thread_bind_mask) != g_marsio4_work_thread_num){
+
+ unsigned int cpu_mask_array[sizeof(cpu_set_t) * 8] = {0};
+ int cpu_mask_num = MESA_load_profile_uint_range((char *)"conf/main.conf", (char *)"Module", (char *)"cpu_bind_core", sizeof(cpu_set_t) * 8, cpu_mask_array);
+ if (cpu_mask_num > 0 )
+ {
+ if (cpu_mask_num != g_marsio4_work_thread_num)
+ {
printf("\033[41m[Error]main.conf->cpu_bind_core_mask value is not match main.conf->threadnum!\033[0m\n");
- printf("\033[41m main.conf->cpu_bind_core_mask bit numer must match main.conf->threadnum, \033[0m\n");
- printf("\033[41m for example, threadnum=8, core_mask shoule be 0xFF, 0xFF0, 0xFF00, etc.\033[0m\n");
- printf("\033[41m for example, threadnum=16, core_mask shoule be 0xFFFF, 0xFFFF0, 0xFFFF00, etc.\033[0m\n");
+ printf("\033[41m main.conf->cpu_bind_core bit numer must match main.conf->threadnum, \033[0m\n");
+ printf("\033[41m for example, threadnum=8, bind_core shoule be 1-8 or 2-9 etc.\033[0m\n");
+ printf("\033[41m for example, threadnum=16, bind_core shoule be 1-16 or 2-17 etc.\033[0m\n");
return -1;
}
- }else if(atoi(bind_mask_string) == 0){
- marsio4_thread_bind_mask = 0;
- printf("\033[33m[Warning]In marsio mode, main.conf->cpu_bind_core_mask value is 0, same as not set, maybe cause CPU preemption!\033[0m\n");
- sleep(1);
- }else{
- printf("\033[41m[Error]main.conf->cpu_bind_core_mask value incorrect!\033[0m\n");
- return -1;
- }
- if(marsio4_thread_bind_mask != 0){
- ret = marsio_option_set(mr4_instance, MARSIO_OPT_THREAD_MASK, &marsio4_thread_bind_mask, sizeof(long));
- if(ret < 0){
- printf("\033[1;31;40m[Error] marsio set CPU-MASK '%lx' failed!\033[0m\n", marsio4_thread_bind_mask);
+ else
+ {
+ cpu_set_t cpu_mask;
+ CPU_ZERO(&cpu_mask);
+ for (i = 0; i < cpu_mask_num; i++)
+ {
+ CPU_SET(cpu_mask_array[i], &cpu_mask);
+ }
+ ret = marsio_option_set(mr4_instance, MARSIO_OPT_THREAD_MASK_IN_CPUSET, &cpu_mask, sizeof(cpu_mask));
+ if (ret < 0)
+ {
+ MESA_load_profile_string_nodef((char *)"conf/main.conf", (char *)"Module", (char *)"cpu_bind_core", bind_mask_string, sizeof(bind_mask_string));
+ printf("\033[1;31;40m[Error] marsio set CPU-MASK '%s' failed!\033[0m\n", bind_mask_string);
+ return 0;
+ }
}
- }
+ }
+ else
+ {
+ ret = MESA_load_profile_string_def((char *)"conf/main.conf", (char *)"Module", (char *)"cpu_bind_core_mask", bind_mask_string, 128, "$");
+ if (bind_mask_string[0] == '$')
+ {
+ marsio4_thread_bind_mask = 0;
+ printf("\033[33m[Warning]In marsio mode, not set main.conf->cpu_bind_core_mask value, maybe cause CPU preemption!\033[0m\n");
+ sleep(1);
+ }
+ else if (strncmp("0x", bind_mask_string, 2) == 0)
+ {
+ marsio4_thread_bind_mask = strtoul(bind_mask_string, NULL, 16);
+ if (calc_integer_bit_num(marsio4_thread_bind_mask) != g_marsio4_work_thread_num)
+ {
+ printf("\033[41m[Error]main.conf->cpu_bind_core_mask value is not match main.conf->threadnum!\033[0m\n");
+ printf("\033[41m main.conf->cpu_bind_core_mask bit numer must match main.conf->threadnum, \033[0m\n");
+ printf("\033[41m for example, threadnum=8, core_mask shoule be 0xFF, 0xFF0, 0xFF00, etc.\033[0m\n");
+ printf("\033[41m for example, threadnum=16, core_mask shoule be 0xFFFF, 0xFFFF0, 0xFFFF00, etc.\033[0m\n");
+ return -1;
+ }
+ }
+ else if (atoi(bind_mask_string) == 0)
+ {
+ marsio4_thread_bind_mask = 0;
+ printf("\033[33m[Warning]In marsio mode, main.conf->cpu_bind_core_mask value is 0, same as not set, maybe cause CPU preemption!\033[0m\n");
+ sleep(1);
+ }
+ else
+ {
+ printf("\033[41m[Error]main.conf->cpu_bind_core_mask value incorrect!\033[0m\n");
+ return -1;
+ }
+ if (marsio4_thread_bind_mask != 0)
+ {
+ ret = marsio_option_set(mr4_instance, MARSIO_OPT_THREAD_MASK, &marsio4_thread_bind_mask, sizeof(long));
+ if (ret < 0)
+ {
+ printf("\033[1;31;40m[Error] marsio set CPU-MASK '%lx' failed!\033[0m\n", marsio4_thread_bind_mask);
+ }
+ }
+ }
+
char app_instance_name[64];
memset(app_instance_name, 0, 64);
@@ -586,7 +609,7 @@ static void *marsio4_worker(void *arg)
sprintf(thread_name, "sapp_marsio_%d", tid);
prctl(PR_SET_NAME, thread_name);
- if(marsio4_thread_bind_mask != 0){
+ if(g_marsio4_work_thread_num != 0){
marsio_thread_init(mr4_instance);
}
memset(&raw_pkt, 0, sizeof(raw_pkt_t));
diff --git a/packet_io/packet_io_status.cpp b/packet_io/packet_io_status.cpp
index f7cbe09..27a50a9 100644
--- a/packet_io/packet_io_status.cpp
+++ b/packet_io/packet_io_status.cpp
@@ -168,7 +168,7 @@ void sysinfo_output(void)
"|--------From-of-startup---------|", "|--------Special---------|");
fprintf(fp,"%3s %8s %9s %10s %10s %10s %10s %9s %13s %17s\n", "tid", "link-syn", "link-data", "link-nouse",
"link-new/s", "link-del/s", "stream-num", "reset-num", "hash-list-max", "special-timeout");
- for(i = 0; i < g_packet_io_thread_num; i++){
+ for(i = 0; i < g_packet_io_thread_num; i++){
fprintf(fp, "%3d %8llu %9llu %10llu %10llu %10llu %10llu %9llu %13llu %13llu\n",
i,
g_SysInputInfo[i][SYS_TCP_LINK_SYN],
@@ -187,7 +187,7 @@ void sysinfo_output(void)
"|--From-of-startup--|", "|--------Special---------|");
fprintf(fp,"%3s %8s %9s %10s %10s %10s %10s %9s %17s\n", "tid", "link-one", "link-two", "link-more", "link-new/s",
"link-del/s", "stream-num", "reset-num", "special-timeout");
- for(i = 0; i < g_packet_io_thread_num; i++){
+ for(i = 0; i < g_packet_io_thread_num; i++){
fprintf(fp, "%3d %8llu %9llu %10llu %10llu %10llu %10llu %9llu %13llu\n",
i,
g_SysInputInfo[i][SYS_UDP_LINK_ONE],
@@ -199,22 +199,24 @@ void sysinfo_output(void)
g_SysInputInfo[i][SYS_UDP_LINK_RESET],
sapp_global_mthread[i].udp_stream_special_timeout_num);
}
-
+
fprintf(fp,"*****************************************************************\n\n");
- fprintf(fp,"################# \033[41m%s\033[0m --- is same as above! #########\n", "sysinfo humanly");
- fprintf(fp,"%-10s %12s %12s %12s %12s\n", "RCV-PKT", "total_pkt", "total_len","pps", "bps");
- fprintf(fp,"%-10s %12llu %12s %12llu %12s\n","Ethernet",sysinfo_new[PKT_ETHERNET],byte_convert_human(sysinfo_new[PKT_ETHERNET_LEN],1 ,1,s1),(sysinfo_new[PKT_ETHERNET]-sysinfo_old[PKT_ETHERNET]),byte_convert_human((sysinfo_new[PKT_ETHERNET_LEN]-sysinfo_old[PKT_ETHERNET_LEN]),1,8,s2));
- fprintf(fp,"%-10s %12llu %12s %12llu %12s\n","IPv4",sysinfo_new[PKT_IP],byte_convert_human(sysinfo_new[PKT_IPLEN],1 ,1,s1),(sysinfo_new[PKT_IP]-sysinfo_old[PKT_IP]),byte_convert_human((sysinfo_new[PKT_IPLEN]-sysinfo_old[PKT_IPLEN]),1,8,s2));
- fprintf(fp,"%-10s %12llu %12s %12llu %12s\n","IPv6",sysinfo_new[PKT_IPV6],byte_convert_human(sysinfo_new[PKT_IPV6LEN],1,1,s1),(sysinfo_new[PKT_IPV6]-sysinfo_old[PKT_IPV6]),byte_convert_human((sysinfo_new[PKT_IPV6LEN]-sysinfo_old[PKT_IPV6LEN]),1,8,s2));
- fprintf(fp,"%-10s %12llu %12s %12llu %12s\n","TCP",sysinfo_new[PKT_TCP],byte_convert_human(sysinfo_new[PKT_TCPLEN],1,1,s1),(sysinfo_new[PKT_TCP]-sysinfo_old[PKT_TCP]),byte_convert_human((sysinfo_new[PKT_TCPLEN]-sysinfo_old[PKT_TCPLEN]),1,8,s2));
- fprintf(fp,"%-10s %12llu %12s %12llu %12s\n","UDP",sysinfo_new[PKT_UDP],byte_convert_human(sysinfo_new[PKT_UDPLEN],1,1,s1),(sysinfo_new[PKT_UDP]-sysinfo_old[PKT_UDP]),byte_convert_human((sysinfo_new[PKT_UDPLEN]-sysinfo_old[PKT_UDPLEN]),1,8,s2));
- fprintf(fp,"%-10s %12llu %12s %12llu %12s\n","Unknown",sysinfo_new[PKT_UNKNOWN],byte_convert_human(sysinfo_new[PKT_UNKNOWN_LEN],1,1,s1),(sysinfo_new[PKT_UNKNOWN]-sysinfo_old[PKT_UNKNOWN]),byte_convert_human((sysinfo_new[PKT_UNKNOWN_LEN]-sysinfo_old[PKT_UNKNOWN_LEN]),1,8,s2));
+ fprintf(fp,"################# \033[41m%s\033[0m --- is same as above! #####################\n", "sysinfo humanly");
+ fprintf(fp,"%-10s %12s %12s %12s %12s %12s\n", "RCV-PKT", "total_pkt", "total_len","pps", "bps", "avg_len");
+ fprintf(fp,"%-10s %12llu %12s %12llu %12s %8lu/%lu\n","Ethernet",sysinfo_new[PKT_ETHERNET],byte_convert_human(sysinfo_new[PKT_ETHERNET_LEN],1 ,1,s1),(sysinfo_new[PKT_ETHERNET]-sysinfo_old[PKT_ETHERNET]),byte_convert_human((sysinfo_new[PKT_ETHERNET_LEN]-sysinfo_old[PKT_ETHERNET_LEN]),1,8,s2),((sysinfo_new[PKT_ETHERNET]-sysinfo_old[PKT_ETHERNET]>0)?(sysinfo_new[PKT_ETHERNET_LEN]-sysinfo_old[PKT_ETHERNET_LEN])/(sysinfo_new[PKT_ETHERNET]-sysinfo_old[PKT_ETHERNET]):0), (sysinfo_new[PKT_ETHERNET]>0)?(sysinfo_new[PKT_ETHERNET_LEN]/sysinfo_new[PKT_ETHERNET]):0);
+ fprintf(fp,"%-10s %12llu %12s %12llu %12s %8lu/%lu\n","IPv4",sysinfo_new[PKT_IP],byte_convert_human(sysinfo_new[PKT_IPLEN],1 ,1,s1),(sysinfo_new[PKT_IP]-sysinfo_old[PKT_IP]),byte_convert_human((sysinfo_new[PKT_IPLEN]-sysinfo_old[PKT_IPLEN]),1,8,s2), ((sysinfo_new[PKT_IP]-sysinfo_old[PKT_IP]>0)?(sysinfo_new[PKT_IPLEN]-sysinfo_old[PKT_IPLEN])/(sysinfo_new[PKT_IP]-sysinfo_old[PKT_IP]):0),(sysinfo_new[PKT_IP]>0)?(sysinfo_new[PKT_IPLEN]/sysinfo_new[PKT_IP]):0);
+ fprintf(fp,"%-10s %12llu %12s %12llu %12s %8lu/%lu\n","IPv6",sysinfo_new[PKT_IPV6],byte_convert_human(sysinfo_new[PKT_IPV6LEN],1,1,s1),(sysinfo_new[PKT_IPV6]-sysinfo_old[PKT_IPV6]),byte_convert_human((sysinfo_new[PKT_IPV6LEN]-sysinfo_old[PKT_IPV6LEN]),1,8,s2),((sysinfo_new[PKT_IPV6]-sysinfo_old[PKT_IPV6]>0)?(sysinfo_new[PKT_IPV6LEN]-sysinfo_old[PKT_IPV6LEN])/(sysinfo_new[PKT_IPV6]-sysinfo_old[PKT_IPV6]):0),(sysinfo_new[PKT_IPV6]>0)?(sysinfo_new[PKT_IPV6LEN]/sysinfo_new[PKT_IPV6]):0);
+ fprintf(fp,"%-10s %12llu %12s %12llu %12s %8lu/%lu\n","TCP",sysinfo_new[PKT_TCP],byte_convert_human(sysinfo_new[PKT_TCPLEN],1,1,s1),(sysinfo_new[PKT_TCP]-sysinfo_old[PKT_TCP]),byte_convert_human((sysinfo_new[PKT_TCPLEN]-sysinfo_old[PKT_TCPLEN]),1,8,s2), ((sysinfo_new[PKT_TCP]-sysinfo_old[PKT_TCP]>0)?(sysinfo_new[PKT_TCPLEN]-sysinfo_old[PKT_TCPLEN])/(sysinfo_new[PKT_TCP]-sysinfo_old[PKT_TCP]):0),(sysinfo_new[PKT_TCP]>0)?(sysinfo_new[PKT_TCPLEN]/sysinfo_new[PKT_TCP]):0);
+ fprintf(fp,"%-10s %12llu %12s %12llu %12s %8lu/%lu\n","UDP",sysinfo_new[PKT_UDP],byte_convert_human(sysinfo_new[PKT_UDPLEN],1,1,s1),(sysinfo_new[PKT_UDP]-sysinfo_old[PKT_UDP]),byte_convert_human((sysinfo_new[PKT_UDPLEN]-sysinfo_old[PKT_UDPLEN]),1,8,s2),((sysinfo_new[PKT_UDP]-sysinfo_old[PKT_UDP]>0)?(sysinfo_new[PKT_UDPLEN]-sysinfo_old[PKT_UDPLEN])/(sysinfo_new[PKT_UDP]-sysinfo_old[PKT_UDP]):0),(sysinfo_new[PKT_UDP]>0)?(sysinfo_new[PKT_UDPLEN]/sysinfo_new[PKT_UDP]):0);
+ fprintf(fp,"%-10s %12llu %12s %12llu %12s %8lu/%lu\n","Unknown",sysinfo_new[PKT_UNKNOWN],byte_convert_human(sysinfo_new[PKT_UNKNOWN_LEN],1,1,s1),(sysinfo_new[PKT_UNKNOWN]-sysinfo_old[PKT_UNKNOWN]),byte_convert_human((sysinfo_new[PKT_UNKNOWN_LEN]-sysinfo_old[PKT_UNKNOWN_LEN]),1,8,s2),((sysinfo_new[PKT_UNKNOWN]-sysinfo_old[PKT_UNKNOWN]>0)?(sysinfo_new[PKT_UNKNOWN_LEN]-sysinfo_old[PKT_UNKNOWN_LEN])/(sysinfo_new[PKT_UNKNOWN]-sysinfo_old[PKT_UNKNOWN]):0),(sysinfo_new[PKT_UNKNOWN]>0)?(sysinfo_new[PKT_UNKNOWN_LEN]/sysinfo_new[PKT_UNKNOWN]):0);
- fprintf(fp,"#################################################################\n");
+ fprintf(fp,"#############################################################################\n");
fprintf(fp,"%-10s %12s %12s\n","TCP_LINK", "total_link", "link/s");
fprintf(fp,"%-10s %12llu %12llu\n", "TCP_NEW", sysinfo_new[SYS_TCP_LINK_NEW],
sysinfo_new[SYS_TCP_LINK_NEW] - sysinfo_old[SYS_TCP_LINK_NEW]);
+ fprintf(fp,"%-10s %12llu %12llu\n", "TCP_DIS", sysinfo_new[TCP_LINK_DISPOSABLE],
+ sysinfo_new[TCP_LINK_DISPOSABLE] - sysinfo_old[TCP_LINK_DISPOSABLE]);
//fprintf(fp,"%-10s %12llu %12llu\n", "TCP_DATA", sysinfo_new[SYS_TCP_LINK_DATA],
// sysinfo_new[SYS_TCP_LINK_DATA] - sysinfo_old[SYS_TCP_LINK_DATA]);
fprintf(fp,"%-10s %12llu %12llu\n", "TCP_DEL", sysinfo_new[SYS_TCP_LINK_DEL],
@@ -226,6 +228,14 @@ void sysinfo_output(void)
fprintf(fp,"%-10s %12llu %12llu\n", "TCP_S2C", sysinfo_new[LINK_SINGLE_S2C],
sysinfo_new[LINK_SINGLE_S2C] - sysinfo_old[LINK_SINGLE_S2C]);
+ fprintf(fp,"#################################################################\n");
+ fprintf(fp,"%-10s %12s %12s\n","UDP_LINK", "total_link", "link/s");
+ fprintf(fp,"%-10s %12llu %12llu\n", "UDP_NEW", sysinfo_new[SYS_UDP_LINK_NEW],
+ sysinfo_new[SYS_UDP_LINK_NEW] - sysinfo_old[SYS_UDP_LINK_NEW]);
+ fprintf(fp,"%-10s %12llu %12llu\n", "UDP_DIS", sysinfo_new[UDP_LINK_DISPOSABLE],
+ sysinfo_new[UDP_LINK_DISPOSABLE] - sysinfo_old[UDP_LINK_DISPOSABLE]);
+
+
fprintf(fp,"#################################################################\n");
fprintf(fp,"%-10s %12s %12s %12s %12s\n","SND-PKT", "total_pkt", "total_len","pps", "bps");
fprintf(fp,"%-10s %12llu %12s %12llu %12s\n", "TCP_RST", sysinfo_new[SEND_TCP_RST], byte_convert_human(sysinfo_new[SEND_TCP_RST_LEN], 1, 1, s1),(sysinfo_new[SEND_TCP_RST]-sysinfo_old[SEND_TCP_RST]), byte_convert_human((sysinfo_new[SEND_TCP_RST_LEN]-sysinfo_old[SEND_TCP_RST_LEN]), 1,8,s2));
diff --git a/plugin/src/plugin.c b/plugin/src/plugin.c
index 0838df0..33feff9 100644
--- a/plugin/src/plugin.c
+++ b/plugin/src/plugin.c
@@ -95,6 +95,9 @@ int stream_register_fun(int funtype,char (*x)(void));
#include <unistd.h>
#include <dlfcn.h>
#include <assert.h>
+#include <bits/time.h>
+#include <time.h>
+#include <stream_register.h>
//#include <readline/readline.h>
//#include <readline/history.h>
#include "MESA_prof_load.h"
@@ -111,8 +114,10 @@ extern stBusinessPlugInfo* g_business_plug_info;
extern stProtocolPlugInfo **g_protocol_plug_info_array;
extern int g_timestamp_record_sw;
extern long long g_timedelay_threshold;
-
-int g_plugin_plugid ;
+extern sapp_fs2_register_plug_id(int plug_id, const char *plug_name);
+extern sapp_fs2_set_plug_init_time(int plug_id, long long time_us);
+int g_plugin_proto_plugid ;
+int g_plugin_other_plugid ;
stEntryNameInfo* g_entryname_info;
/*
@@ -693,16 +698,20 @@ int process_confelem_sofilename(char* filename,int plugtype,stProtocolPlugInfo*
}
-
+ struct timespec start, end;
+ long elapsed = 0;
+ clock_gettime(CLOCK_MONOTONIC, &start);
+
rec = fun_init();
if(rec < 0)
{
MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s init error,don't load it\n",buf_sofilename);
return -1;
}
+ clock_gettime(CLOCK_MONOTONIC, &end);
+ elapsed = (end.tv_sec - start.tv_sec)*1000000 + (end.tv_nsec - start.tv_nsec)/1000;
-
- //load FUNNAME_DESTROY
+ //load FUNNAME_DESTROY
memset(buf_funname,0,PLUGIN_MAX_CONFLEN);
MESA_load_profile_string_nodef(filename,SECTION_PLUGINFO,KEYWORD_FUNDESTROY,buf_funname,PLUGIN_MAX_CONFLEN);
if(buf_funname[0] !='\0')
@@ -745,7 +754,6 @@ int process_confelem_sofilename(char* filename,int plugtype,stProtocolPlugInfo*
pluginfo_pro->filepoint = filepoint;
pluginfo_pro->fun_destroy = fun_destroy;
-
//dlsym GET_PLUGID()
memset(buf_funname,0,PLUGIN_MAX_CONFLEN);
MESA_load_profile_string_nodef(filename,SECTION_PLUGINFO,KEYWORD_FUNGETID,buf_funname,PLUGIN_MAX_CONFLEN);
@@ -767,10 +775,11 @@ int process_confelem_sofilename(char* filename,int plugtype,stProtocolPlugInfo*
}
-
- g_plugin_plugid++;
- fun_getplugid(g_plugin_plugid);
- pluginfo_pro->plugid = g_plugin_plugid;
+ g_plugin_proto_plugid++;
+ fun_getplugid(g_plugin_proto_plugid);
+ pluginfo_pro->plugid = g_plugin_proto_plugid;
+ sapp_fs2_register_plug_id(g_plugin_proto_plugid, pluginfo_pro->plugname);
+ sapp_fs2_set_plug_init_time(g_plugin_proto_plugid, elapsed);
//dlsym flag_change
memset(buf_funname,0,PLUGIN_MAX_CONFLEN);
@@ -793,7 +802,6 @@ int process_confelem_sofilename(char* filename,int plugtype,stProtocolPlugInfo*
}
-
//dlsym flag_state
memset(buf_funname,0,PLUGIN_MAX_CONFLEN);
MESA_load_profile_string_nodef(filename,SECTION_PLUGINFO,KEYWORD_FUNSTATE,buf_funname,PLUGIN_MAX_CONFLEN);
@@ -817,8 +825,13 @@ int process_confelem_sofilename(char* filename,int plugtype,stProtocolPlugInfo*
//business plug
else
{
+ g_plugin_other_plugid+=1;
+ sapp_fs2_register_plug_id(g_plugin_other_plugid + MAX_FUN_NUM, pluginfo_bus->plugname);
+ sapp_fs2_set_plug_init_time(g_plugin_other_plugid + MAX_FUN_NUM, elapsed);
+
pluginfo_bus->filepoint = filepoint;
pluginfo_bus->fun_destroy = fun_destroy;
+ pluginfo_bus->plugid = g_plugin_other_plugid+MAX_FUN_NUM;
// pluginfo_bus->fun_update = (int (*)(int,int,char*,char*))(dlsym(filepoint,FUNNAME_UPDATE));
}
diff --git a/plugin/src/plugin_protocol.c b/plugin/src/plugin_protocol.c
index a8e1064..a11f1f3 100644
--- a/plugin/src/plugin_protocol.c
+++ b/plugin/src/plugin_protocol.c
@@ -1,168 +1,168 @@
-#include <stdio.h>
-#include <string.h>
-#include <dlfcn.h>
-#include "MESA_prof_load.h"
-#include "MESA_handle_logger.h"
-#include "stream.h"
-#include "plugin_proc.h"
-#include "plugin_platform.h"
-#include "plugin_protocol.h"
-#include "plugin_business.h"
-#include "plugin.h"
-
-stProtocolPlugInfo* g_protocol_plug_info;
-stProtocolPlugInfo **g_protocol_plug_info_array;
-extern int g_plugin_plugid;
-extern int process_confelem_sofilename(char* filename,int plugtype,stProtocolPlugInfo* pluginfo_pro,stBusinessPlugInfo* pluginfo_bus);
-extern int process_confelem_platentry(char* filename,void* fp_dlopen,char* plugname);
-
-
-/* 2016-05-30 lijia add, Ϊ�˸��Ƶ��ò������, ����ÿ�ζ���������, ��ָ��洢������, ֱ��ȡ�±� */
-static void plugin_protocol_info_convert(void)
-{
- int i;
- stProtocolPlugInfo *tmp_plug_info = g_protocol_plug_info;
-
- if(NULL == g_protocol_plug_info){
- return;
- }
-
- g_protocol_plug_info_array = malloc(sizeof(void *) * (g_plugin_plugid + 1));
- memset(g_protocol_plug_info_array, 0, sizeof(void *) * (g_plugin_plugid + 1));
-
- while(tmp_plug_info->next){
- tmp_plug_info = tmp_plug_info->next;
- }
-
- for(i = 1; i <= g_plugin_plugid; i++){
- g_protocol_plug_info_array[i] = tmp_plug_info;
- if(NULL == tmp_plug_info){
- break;
- }
- tmp_plug_info = tmp_plug_info->pre;
- }
-}
-
-/****************************************************************************
-������:plugin_load_protocol()
-���ܣ������������������ļ��б�
-���룺�������������ļ��б�ȫ·����
-�����0:sucess
- -1:error
-*****************************************************************************/
-int plugin_load_protocol(char* conflist_filename)
-{
- int rec;
-
- rec = process_conflist(conflist_filename,PLUGTYPE_PROTOCOL);
- if(rec < 0)
- {
- return -1;
- }
-
- plugin_protocol_info_convert();
-
- return 0;
-}
-
-
-
-/****************************************************************************
-������:init_pluginfo_elem_pro()
-���ܣ���������������Ϣ
-���룺
-�����
-*****************************************************************************/
-void init_pluginfo_elem_pro(stProtocolPlugInfo** protocol_plug_info)
-{
- stProtocolPlugInfo* plug_info = (stProtocolPlugInfo*)malloc(sizeof(stProtocolPlugInfo));
- memset(plug_info,0,sizeof(stProtocolPlugInfo));
-
- *protocol_plug_info = plug_info;
-
- return;
-}
-
-/****************************************************************************
-������:destroy_pluginfo_elem_pro()
-���ܣ��ͷŽ���������Ϣ
-���룺
-�����
-*****************************************************************************/
-void destroy_pluginfo_elem_pro(stProtocolPlugInfo* plug_info)
-{
- if(plug_info->plugname != NULL)
- {
- free(plug_info->plugname);
- plug_info->plugname = NULL;
- }
-
- free(plug_info);
- plug_info = NULL;
-
- return;
-
-}
-
-/****************************************************************************
-������:process_confelem_protocol()
-���ܣ����������������������ļ�������̬���ز������
-���룺�������������ļ�ȫ·����
-�����0:sucess
- -1:error
-*****************************************************************************/
-int process_confelem_protocol(char* confelem_filename)
-{
- int rec;
- stProtocolPlugInfo* plug_info;
-
-
- init_pluginfo_elem_pro(&plug_info);
-
-
- //PLUGNAME
- rec = process_confelem_plugname(confelem_filename,PLUGTYPE_PROTOCOL,&(plug_info->plugname));
- if(rec < 0)
- {
- destroy_pluginfo_elem_pro(plug_info);
- return -1;
- }
-
- //FILENAME
- rec = process_confelem_sofilename(confelem_filename,PLUGTYPE_PROTOCOL,plug_info,NULL);
- if(rec < 0)
- {
- destroy_pluginfo_elem_pro(plug_info);
- return -1;
- }
-
-
- //[IP],[IPV6],[TCP],[UDP]
- rec = process_confelem_platentry(confelem_filename,plug_info->filepoint,plug_info->plugname);
-
- if(rec < 0)
- {
- destroy_pluginfo_elem_pro(plug_info);
- return -1;
- }
-
-
- //add plug_info to protocol_plug_info's double dir link table
- if(g_protocol_plug_info == NULL)
- {
- g_protocol_plug_info = plug_info;
- }
- else
- {
- plug_info->next = g_protocol_plug_info;
- g_protocol_plug_info->pre = plug_info;
- g_protocol_plug_info = plug_info;
- }
-
- printf("\033[32m[Notice]%s, load %s success!\033[0m\n", PLUGIN_LOGNAME, plug_info->plugname);
- MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_FATAL, PLUGIN_LOGNAME,"load %s success!\n",plug_info->plugname);
-
- return 0;
-
-}
-
+#include <stdio.h>
+#include <string.h>
+#include <dlfcn.h>
+#include "MESA_prof_load.h"
+#include "MESA_handle_logger.h"
+#include "stream.h"
+#include "plugin_proc.h"
+#include "plugin_platform.h"
+#include "plugin_protocol.h"
+#include "plugin_business.h"
+#include "plugin.h"
+
+stProtocolPlugInfo* g_protocol_plug_info;
+stProtocolPlugInfo **g_protocol_plug_info_array;
+extern int g_plugin_proto_plugid;
+extern int process_confelem_sofilename(char* filename,int plugtype,stProtocolPlugInfo* pluginfo_pro,stBusinessPlugInfo* pluginfo_bus);
+extern int process_confelem_platentry(char* filename,void* fp_dlopen,char* plugname);
+
+
+/* 2016-05-30 lijia add, Ϊ�˸��Ƶ��ò������, ����ÿ�ζ���������, ��ָ��洢������, ֱ��ȡ�±� */
+static void plugin_protocol_info_convert(void)
+{
+ int i;
+ stProtocolPlugInfo *tmp_plug_info = g_protocol_plug_info;
+
+ if(NULL == g_protocol_plug_info){
+ return;
+ }
+
+ g_protocol_plug_info_array = malloc(sizeof(void *) * (g_plugin_proto_plugid + 1));
+ memset(g_protocol_plug_info_array, 0, sizeof(void *) * (g_plugin_proto_plugid + 1));
+
+ while(tmp_plug_info->next){
+ tmp_plug_info = tmp_plug_info->next;
+ }
+
+ for(i = 1; i <= g_plugin_proto_plugid; i++){
+ g_protocol_plug_info_array[i] = tmp_plug_info;
+ if(NULL == tmp_plug_info){
+ break;
+ }
+ tmp_plug_info = tmp_plug_info->pre;
+ }
+}
+
+/****************************************************************************
+������:plugin_load_protocol()
+���ܣ������������������ļ��б�
+���룺�������������ļ��б�ȫ·����
+�����0:sucess
+ -1:error
+*****************************************************************************/
+int plugin_load_protocol(char* conflist_filename)
+{
+ int rec;
+
+ rec = process_conflist(conflist_filename,PLUGTYPE_PROTOCOL);
+ if(rec < 0)
+ {
+ return -1;
+ }
+
+ plugin_protocol_info_convert();
+
+ return 0;
+}
+
+
+
+/****************************************************************************
+������:init_pluginfo_elem_pro()
+���ܣ���������������Ϣ
+���룺
+�����
+*****************************************************************************/
+void init_pluginfo_elem_pro(stProtocolPlugInfo** protocol_plug_info)
+{
+ stProtocolPlugInfo* plug_info = (stProtocolPlugInfo*)malloc(sizeof(stProtocolPlugInfo));
+ memset(plug_info,0,sizeof(stProtocolPlugInfo));
+
+ *protocol_plug_info = plug_info;
+
+ return;
+}
+
+/****************************************************************************
+������:destroy_pluginfo_elem_pro()
+���ܣ��ͷŽ���������Ϣ
+���룺
+�����
+*****************************************************************************/
+void destroy_pluginfo_elem_pro(stProtocolPlugInfo* plug_info)
+{
+ if(plug_info->plugname != NULL)
+ {
+ free(plug_info->plugname);
+ plug_info->plugname = NULL;
+ }
+
+ free(plug_info);
+ plug_info = NULL;
+
+ return;
+
+}
+
+/****************************************************************************
+������:process_confelem_protocol()
+���ܣ����������������������ļ�������̬���ز������
+���룺�������������ļ�ȫ·����
+�����0:sucess
+ -1:error
+*****************************************************************************/
+int process_confelem_protocol(char* confelem_filename)
+{
+ int rec;
+ stProtocolPlugInfo* plug_info;
+
+
+ init_pluginfo_elem_pro(&plug_info);
+
+
+ //PLUGNAME
+ rec = process_confelem_plugname(confelem_filename,PLUGTYPE_PROTOCOL,&(plug_info->plugname));
+ if(rec < 0)
+ {
+ destroy_pluginfo_elem_pro(plug_info);
+ return -1;
+ }
+
+ //FILENAME
+ rec = process_confelem_sofilename(confelem_filename,PLUGTYPE_PROTOCOL,plug_info,NULL);
+ if(rec < 0)
+ {
+ destroy_pluginfo_elem_pro(plug_info);
+ return -1;
+ }
+
+
+ //[IP],[IPV6],[TCP],[UDP]
+ rec = process_confelem_platentry(confelem_filename,plug_info->filepoint,plug_info->plugname);
+
+ if(rec < 0)
+ {
+ destroy_pluginfo_elem_pro(plug_info);
+ return -1;
+ }
+
+
+ //add plug_info to protocol_plug_info's double dir link table
+ if(g_protocol_plug_info == NULL)
+ {
+ g_protocol_plug_info = plug_info;
+ }
+ else
+ {
+ plug_info->next = g_protocol_plug_info;
+ g_protocol_plug_info->pre = plug_info;
+ g_protocol_plug_info = plug_info;
+ }
+
+ printf("\033[32m[Notice]%s, load %s success!\033[0m\n", PLUGIN_LOGNAME, plug_info->plugname);
+ MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_FATAL, PLUGIN_LOGNAME,"load %s success!\n",plug_info->plugname);
+
+ return 0;
+
+}
+
diff --git a/run/conf/main.conf b/run/conf/main.conf
index ef9853b..e54bf3f 100644
--- a/run/conf/main.conf
+++ b/run/conf/main.conf
@@ -1,8 +1,6 @@
[Module]
-
threadnum=1
-#cpu_bind_core_mask=1,2,3,4,5
-cpu_bind_core_mask=0xFF0
+cpu_bind_core=1
app_instance_name=sapp
MaxTcpStreams=1000
MaxUdpStreams=1000
@@ -50,7 +48,7 @@ encapsulate_with_L2E=0
maxrandval=65535
randkeyval=13
-kill_tcp_rst_pkt_num=3
+kill_tcp_rst_pkt_num=1
kill_tcp_rst_signature=0
raw_pkt_broken_check=0
@@ -91,7 +89,7 @@ iknow_switch=0
iknow_listen_port=65432
platform_log_level=30
-FS_switch=1
+FS_switch=0
FS_cycle=3
FS_print_switch=1
FS_server_ip=127.0.0.1