summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordump2file <[email protected]>2019-01-08 14:55:23 +0600
committerdump2file <[email protected]>2019-01-08 14:55:23 +0600
commit14ad4a10c2d5e17c9a3de78e0b29065aad4baa37 (patch)
tree29d9779b5061f14a4bf596e7067c75b009f7c736
parent02e59a44174f99cdce298104c2eab18b82cd3636 (diff)
1、inner_plug目录的cmakelist增加平台携带的.so插件管理,包括pptp,l2tp,iskamp,g_dev_plug等
2、test_so增加cmakelist 3、顶层cmakelist增加install内容,从编译的.so更新安装目录 4、g_dev_plug调整,对于gdev.conf中gdev_status_switch为0的情况,仅对vxlan_sport_service_map.conf中配置的service进行保活,其余包括开关为0
-rw-r--r--CMakeLists.txt74
-rw-r--r--inner_plug/CMakeLists.txt28
-rw-r--r--inner_plug/g_device_plug.c1548
-rw-r--r--packet_io/CMakeLists.txt5
-rw-r--r--run/conf/gdev_block.conf14
-rw-r--r--run/conf/send_gdev.conf2
-rw-r--r--run/conf/send_route.conf2
-rw-r--r--test_so/CMakeLists.txt31
-rw-r--r--test_so/Makefile18
-rw-r--r--test_so/sysinfo.log46
10 files changed, 935 insertions, 833 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b32e37f..8cb043d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,6 +3,28 @@ cmake_minimum_required(VERSION 2.8)
set(CMAKE_MACOSX_RPATH 0)
+#set(CMAKE_INSTALL_PREFIX /home/ceiec/sapp/)
+set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/run/)
+
+#static link option
+option(ENABLE_STATIC_LINK "Enable static link" FALSE)
+
+#ASAN option
+option(ENABLE_SANITIZE_ADDRESS "Enable AddressSanitizer" FALSE)
+option(ENABLE_SANITIZE_THREAD "Enable ThreadSanitizer" FALSE)
+
+if(ENABLE_SANITIZE_ADDRESS)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -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)
+ 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")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
+endif()
+
# MESA SDK Root
set(MESA_SDK_PREFIX "/opt/MESA/" CACHE STRING "MESA Framework Prefix")
# Capture Mode
@@ -91,3 +113,55 @@ add_subdirectory(plugin)
add_subdirectory(project)
add_subdirectory(inner_plug)
add_subdirectory(entry)
+add_subdirectory(test_so)
+
+install(PROGRAMS ${CMAKE_BINARY_DIR}/entry/sapp DESTINATION .)
+
+install(PROGRAMS run/r2 DESTINATION .)
+install(PROGRAMS run/r3 DESTINATION .)
+install(PROGRAMS run/vv.py DESTINATION .)
+install(PROGRAMS run/pag.conf DESTINATION .)
+install(PROGRAMS run/memchk.sh DESTINATION .)
+install(FILES run/conf/gdev_block.conf DESTINATION conf)
+install(FILES run/conf/gdev.conf DESTINATION conf)
+install(FILES run/conf/main.conf DESTINATION conf)
+install(FILES run/conf/project_list.conf DESTINATION conf)
+install(FILES run/conf/route_table.conf DESTINATION conf)
+install(FILES run/conf/send_gdev.conf DESTINATION conf)
+install(FILES run/conf/send_raw_pkt.conf DESTINATION conf)
+install(FILES run/conf/send_route.conf DESTINATION conf)
+install(FILES run/conf/streamid.txt DESTINATION conf)
+install(FILES run/conf/plugin/entrylist.conf DESTINATION conf/plugin)
+install(FILES run/conf/plugin/plugin.conf DESTINATION conf/plugin)
+
+if(CAPTURE_MODE MATCHES "MARSIO")
+ install(FILES ${CMAKE_BINARY_DIR}/packet_io/packet_io_marsio.so DESTINATION platform_lib)
+endif()
+
+if(CAPTURE_MODE MATCHES "PCAP")
+ install(FILES ${CMAKE_BINARY_DIR}/packet_io/packet_io_pcap.so DESTINATION platform_lib)
+endif()
+
+install(FILES run/plug/protocol/conflist_protocol.inf DESTINATION plug/protocol)
+
+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)
+
+install(FILES run/plug/protocol/l2tp_protocol_plug/l2tp_protocol_plug.inf DESTINATION plug/protocol/l2tp_protocol_plug)
+install(FILES ${CMAKE_BINARY_DIR}/inner_plug/l2tp_protocol_plug.so DESTINATION plug/protocol/l2tp_protocol_plug)
+
+install(FILES run/plug/protocol/pptp_protocol_plug/pptp_protocol_plug.inf DESTINATION plug/protocol/pptp_protocol_plug)
+install(FILES ${CMAKE_BINARY_DIR}/inner_plug/pptp_protocol_plug.so DESTINATION plug/protocol/pptp_protocol_plug)
+
+
+install(FILES run/plug/platform/conflist_platform.inf DESTINATION plug/platform)
+
+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)
+
+install(FILES run/plug/business/conflist_business.inf DESTINATION plug/business)
+
+install(FILES run/plug/business/conflist_business.inf DESTINATION plug/business)
+install(FILES run/plug/business/test_app/test_app.inf DESTINATION plug/business/test_app)
+install(FILES ${CMAKE_BINARY_DIR}/test_so/test_app_sapp.so DESTINATION plug/business/test_app)
+install(FILES ${CMAKE_BINARY_DIR}/test_so/trace_delay.so DESTINATION plug/business/test_app)
diff --git a/inner_plug/CMakeLists.txt b/inner_plug/CMakeLists.txt
index 390aa7a..b6d7d0f 100644
--- a/inner_plug/CMakeLists.txt
+++ b/inner_plug/CMakeLists.txt
@@ -17,8 +17,28 @@ endif()
add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H)
add_definitions(-fPIC)
-add_library(sapp_assistant SHARED sapp_assistant.cpp)
-add_library(gdev_assistant SHARED gdev_assistant.c)
+add_library(l2tp_protocol_plug SHARED l2tp_protocol_plug.c)
+set_target_properties(l2tp_protocol_plug PROPERTIES PREFIX "")
-install(TARGETS sapp_assistant DESTINATION ${MESA_SDK_PREFIX}/lib/)
-install(TARGETS gdev_assistant DESTINATION ${MESA_SDK_PREFIX}/lib/)
+add_library(pptp_protocol_plug SHARED pptp_protocol_plug.c)
+set_target_properties(pptp_protocol_plug PROPERTIES PREFIX "")
+
+add_library(isakmp_protocol_plug SHARED isakmp_protocol_plug_add_nat.c)
+set_target_properties(isakmp_protocol_plug PROPERTIES PREFIX "")
+
+add_library(wangyan_keepalive_plug SHARED wangyan_keepalive_plug.c)
+set_target_properties(wangyan_keepalive_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)
+ add_library(sapp_assistant STATIC sapp_assistant.cpp)
+ add_library(gdev_assistant STATIC gdev_assistant.c)
+else()
+ add_library(sapp_assistant SHARED sapp_assistant.cpp)
+ add_library(gdev_assistant SHARED gdev_assistant.c)
+
+ install(TARGETS sapp_assistant DESTINATION ${MESA_SDK_PREFIX}/lib/)
+ install(TARGETS gdev_assistant DESTINATION ${MESA_SDK_PREFIX}/lib/)
+endif()
diff --git a/inner_plug/g_device_plug.c b/inner_plug/g_device_plug.c
index 2259e73..2875e06 100644
--- a/inner_plug/g_device_plug.c
+++ b/inner_plug/g_device_plug.c
@@ -1,772 +1,776 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
- ��wangyanƽ̨��������, �Ƿ���GDEV�����Ǹ��ݲ��������״̬��̬����, �������ٹ̶�һֱ����,
-
- ���Խ�GDEV-KEEPALIVE���ܴ�ƽ̨�а���,
- ���ص�IP��UDP�������ԭ�б����.
-
- Ŀǰû��arp_entry, ethernet_entry, ARP�ظ�������ʱ������ƽ̨�ڲ�.
-*/
-
-#include <pthread.h>
-#ifndef __FAVOR_BSD
-#define __FAVOR_BSD 1
-#endif
-
-#include <arpa/inet.h>
-#include <netinet/udp.h>
-#include <stdlib.h>
-#include "stream_internal.h"
-#include "stream_manage.h"
-#include "logger.h"
-#include "packet_io.h"
-#include "g_device.h"
-#include "mesa_net.h"
-#include "packet_io_internal.h"
-#include "sendpacket.h"
-#include "deal_ipv4.h"
-#include "MESA_prof_load.h"
-#include "MESA_handle_logger.h"
-#include "gdev_keepalive.h"
-#include "stream_rawpkt.h"
-
-#if IOMODE_MARSIO
-#include "marsio.h"
-extern struct mr_instance * sapp_marsio4_instance;
-extern int marsio_send_burst_with_options_for_tcpdumpmesa(struct mr_sendpath * sendpath, queue_id_t sid, marsio_buff_t * mbufs[], int nr_mbufs, uint16_t options);
-
-#endif
-
-int gdev_keepalive_plug_version_VERSION_20180305;
-
-#define MAX_GDEV_STAT_LOG_NUM (64)
-
-static void *gdev_kp_log_handle;
-enum prog_work_mode_t{
- PROG_MODE_MASTER = 1,
- PROG_MODE_SLAVE = 2,
-};
-
-typedef struct {
- int active_flag; /* ��IP���� */
- int gdev_keepalive_type;
- int gdev_keepalive_service_num; /* BFD��ȡ */
- unsigned int gdev_ip_network_order;
- unsigned int tot_rcv_pkt_num;
- unsigned int tot_snd_pkt_num;
- time_t last_time;
- char __pad__[32]; /* 64byte cache aligned */
-}gdev_keepalive_status_t;
-
-static gdev_keepalive_status_t GDEV_KEEPALIVE_STAT[MAX_THREAD_NUM][MAX_GDEV_STAT_LOG_NUM];
-
-static int g_dev_keepalive_flag = 1; /* ȫ�ֱ����־, ���в���������������Ҫ������������ */
-
-#define MAX_VXLAN_SERVICE_NUM (256) /* Ŀǰ���֧��255�ֲ�ͬҵ�� */
-static struct gdev_keepalive_service_ctrl g_dev_keepalive_service_ctrl_array[MAX_VXLAN_SERVICE_NUM];/* ����ij��ҵ����Ƿ񱣻� */
-#define VXLAN_SPORT_SERVICE_MAP_FILE "./conf/vxlan_sport_service_map.conf"
-
-static int GDEV_KEEPALIVE_LOG_SWITCH = 1;
-
-extern int g_packet_io_thread_num;
-extern time_t g_CurrentTime;
-static int g_dev_keepalive_default_action = 1; /* ����g_dev_keepalive_service_ctrl_array��û�е�ҵ���, �DZ���Dz����� */
-static unsigned int sendto_gdev_card_ip; /* ��Gdev����������IP��ַ, ������, network-order */
-extern int g_topology_mode;
-extern int sendpacket_build_icmpv4_echo(u_int8_t type, u_int8_t code, u_int16_t sum,
- u_int16_t id, u_int16_t seq, u_int8_t *payload, u_int32_t payload_s, unsigned char *buf);
-extern char *timet_to_str(time_t timet, char *time_str, int time_str_len);
-static int vxlan_sport_service_map_init(void);
-extern void del_last_rn(char *data, int max_len);
-
-
-static int gdev_kp_action_judge(int service_id)
-{
- if(0 == g_dev_keepalive_flag){
- return 0;
- }
-
- return g_dev_keepalive_service_ctrl_array[service_id].keepalive_switch;
-}
-
-
-static void gdev_keepalive_stat_update(int tid, unsigned int gip_net, int type, int service_id, int action)
-{
- int index;
-
- for(index = 0; index < MAX_GDEV_STAT_LOG_NUM; index++){
- if(0 == GDEV_KEEPALIVE_STAT[tid][index].active_flag){
- break;
- }
- if((gip_net == GDEV_KEEPALIVE_STAT[tid][index].gdev_ip_network_order)
- &&(service_id == GDEV_KEEPALIVE_STAT[tid][index].gdev_keepalive_service_num)
- && (type == GDEV_KEEPALIVE_STAT[tid][index].gdev_keepalive_type)){
- GDEV_KEEPALIVE_STAT[tid][index].last_time = g_CurrentTime;
- GDEV_KEEPALIVE_STAT[tid][index].tot_rcv_pkt_num++;
- GDEV_KEEPALIVE_STAT[tid][index].tot_snd_pkt_num += action;
- return;
- }
- }
-
- /* not found, check number */
- if(index >= MAX_GDEV_STAT_LOG_NUM){
- MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]",
- "Too many gdev ip, moren than %d!\n",
- MAX_GDEV_STAT_LOG_NUM);
- return;
- }
-
- GDEV_KEEPALIVE_STAT[tid][index].active_flag = 1;
- GDEV_KEEPALIVE_STAT[tid][index].gdev_keepalive_type = type;
- GDEV_KEEPALIVE_STAT[tid][index].gdev_keepalive_service_num = service_id;
- GDEV_KEEPALIVE_STAT[tid][index].gdev_ip_network_order = gip_net;
- GDEV_KEEPALIVE_STAT[tid][index].tot_rcv_pkt_num = 1;
- GDEV_KEEPALIVE_STAT[tid][index].tot_snd_pkt_num = action;
- GDEV_KEEPALIVE_STAT[tid][index].last_time = g_CurrentTime;
- return;
-}
-
-/* �����豸�������BFDЭ�� */
-static int gdev_keepalive_bfd_plug(const raw_pkt_t *raw_pkt, int thread_id, unsigned char dir, unsigned char *send_buf)
-{
- char payload_buf[1472];
- struct mesa_ethernet_hdr *eth_hdr = (struct mesa_ethernet_hdr *)raw_pkt->raw_pkt_data;
- struct mesa_ip4_hdr *ip_hdr = (struct mesa_ip4_hdr *)((char *)eth_hdr+ SENDPACKET_ETH_H);
- struct mesa_udp_hdr *udp_hdr = (struct mesa_udp_hdr *)((char *)eth_hdr + SENDPACKET_ETH_H + ip_hdr->ip_hl*4);
- bfd_header_t *bfd_net_hdr = (bfd_header_t *)((char *)eth_hdr + SENDPACKET_ETH_H + ip_hdr->ip_hl*4 + SENDPACKET_UDP_H);
- bfd_header_t *bfd_send_hdr = (bfd_header_t *)payload_buf;
- char bfd_buf[4];
- int payload_len = ntohs(udp_hdr->uh_ulen) - SENDPACKET_UDP_H;
- int service_id = 0;
- int action;
-
-#if 0 /* ��ΪUDP���, ��gdev_bfd_pkt_identify�Ѿ��жϹ�, �����ٴ��ж� */
- if(ntohs(eth_hdr->ether_type) != ETHERTYPE_IP){
- return -1;
- }
-
- if(ip_hdr->ip_p != IPPROTO_UDP){
- return -1;
- }
-
- if(ntohs(udp_hdr->uh_dport) != BFD_DEFAULT_PORT){
- return -1;
- }
-
- if(memcmp(&ip_hdr->ip_dst.s_addr, &sendto_gdev_card_ip, sizeof(int)) != 0){
- return -1;
- }
-
- if(payload_len != (int)sizeof(bfd_header_t)){
- return -1;
- }
-#endif
-
- service_id = vxlan_sport_map_to_service_id(ntohs(udp_hdr->uh_sport));
- action = gdev_kp_action_judge(service_id);
-
- gdev_keepalive_stat_update(thread_id, ip_hdr->ip_src.s_addr, GDEV_KEEPALIVE_TYPE_BFD, service_id, action);
-
- if(0 == action){
- return -1;
- }
- /* ��ȡ����service_id, ����Ӧ�ûظ�����Ӧ��, go on !! */
-
- memcpy(payload_buf, bfd_net_hdr, payload_len);
-
- memcpy(bfd_buf, bfd_send_hdr->my_discriminator, 4);
- memcpy(bfd_send_hdr->my_discriminator, bfd_send_hdr->your_discriminator, 4);
- memcpy(bfd_send_hdr->your_discriminator, bfd_buf, 4);
-
- sendpacket_build_udp_dual_stack(ntohs(udp_hdr->uh_sport), /* BFDЭ�鲻����Դ��Ŀ�Ķ˿� */
- ntohs(udp_hdr->uh_dport),
- (char *)bfd_send_hdr,
- payload_len,
- payload_len,
- send_buf + SENDPACKET_ETH_H + SENDPACKET_IP_H);
-
- sendpacket_build_ipv4(SENDPACKET_UDP_H + payload_len,
- 0,
- ntohs(ip_hdr->ip_id),
- ntohs(ip_hdr->ip_off),
- ip_hdr->ip_ttl,
- IPPROTO_UDP,
- ip_hdr->ip_dst.s_addr,
- ip_hdr->ip_src.s_addr, /* ����Դ��Ŀ��IP��ַ */
- NULL, 0,
- send_buf + SENDPACKET_ETH_H);
-
- sendpacket_do_checksum(send_buf + SENDPACKET_ETH_H,
- IPPROTO_IP,
- SENDPACKET_IP_H);
-
- sendpacket_do_checksum(send_buf + SENDPACKET_ETH_H,
- IPPROTO_UDP,
- payload_len + SENDPACKET_UDP_H);
-
-
- return SENDPACKET_IP_H + SENDPACKET_UDP_H+sizeof(bfd_header_t);
-}
-
-/* �����豸�������BFDЭ�� */
-static int gdev_keepalive_icmp_plug(const raw_pkt_t *raw_pkt, int thread_id, unsigned char dir, unsigned char *send_buf)
-{
- struct mesa_ethernet_hdr *eth_hdr = (struct mesa_ethernet_hdr *)raw_pkt->raw_pkt_data;
- struct mesa_ip4_hdr *ip_hdr = (struct mesa_ip4_hdr *)((char *)eth_hdr + SENDPACKET_ETH_H);
- struct mesa_icmp_echo_hdr *icmp_hdr = (struct mesa_icmp_echo_hdr *)((char *)eth_hdr + SENDPACKET_ETH_H + ip_hdr->ip_hl*4);
- unsigned char *icmp_payload;
- int icmp_payload_len;
-
- gdev_keepalive_stat_update(thread_id, ip_hdr->ip_src.s_addr, GDEV_KEEPALIVE_TYPE_ICMP, 0, g_dev_keepalive_default_action);
-
- icmp_payload = (unsigned char *)icmp_hdr + sizeof(struct mesa_icmp_echo_hdr);
- icmp_payload_len = ntohs(ip_hdr->ip_len) - ip_hdr->ip_hl*4 - sizeof(struct mesa_icmp_echo_hdr);
-
-
- sendpacket_build_icmpv4_echo(ICMP_ECHOREPLY, 0, 0,
- ntohs(icmp_hdr->icd_id),
- ntohs(icmp_hdr->icd_seq),
- icmp_payload,
- icmp_payload_len,
- send_buf + SENDPACKET_ETH_H + SENDPACKET_IP_H);
-
- sendpacket_build_ipv4(icmp_payload_len + sizeof(struct mesa_icmp_echo_hdr),
- 0, 0x1234, 0, 64, IPPROTO_ICMP,
- ip_hdr->ip_dst.s_addr,
- ip_hdr->ip_src.s_addr,
- NULL, 0,
- send_buf + SENDPACKET_ETH_H);
- memcpy(send_buf + SENDPACKET_ETH_H+SENDPACKET_IP_H+sizeof(struct mesa_icmp_echo_hdr),
- icmp_payload,
- icmp_payload_len);
-
-
- sendpacket_do_checksum(send_buf + SENDPACKET_ETH_H,
- IPPROTO_IP,
- SENDPACKET_IP_H);
-
- sendpacket_do_checksum(send_buf + SENDPACKET_ETH_H,
- IPPROTO_ICMP,
- icmp_payload_len + sizeof(struct mesa_icmp_echo_hdr));
-
- return ntohs(ip_hdr->ip_len);
-}
-
-
-static int gdev_keepalive_plug(const raw_pkt_t *raw_pkt, int thread_id, unsigned char dir, int keepalive_type)
-{
- int ret = -1, send_len;
- MESA_send_handle *snd_handle = NULL;
-#if IOMODE_MARSIO
- const struct mesa_ethernet_hdr *raw_eth_hdr = (struct mesa_ethernet_hdr *)raw_pkt->raw_pkt_data;
- struct mesa_ethernet_hdr *snd_eth_hdr;
-#endif
-
- snd_handle = packet_io_get_send_handle(thread_id);
- if(NULL == snd_handle){
- return -1;
- }
- snd_handle->send_buf = packet_io_get_sendbuf(SEND_TYPE_LINK_INJECT, thread_id);
- if(NULL == snd_handle->send_buf){
- return 0;
- }
-
- switch(keepalive_type){
- case GDEV_KEEPALIVE_TYPE_BFD:
- send_len = gdev_keepalive_bfd_plug(raw_pkt, thread_id, dir, snd_handle->send_buf);
- if(send_len < 0){
- goto err;
- }
- break;
-
- case GDEV_KEEPALIVE_TYPE_ICMP:
- send_len = gdev_keepalive_icmp_plug(raw_pkt, thread_id, dir, snd_handle->send_buf);
- if(send_len < 0){
- goto err;
- }
- break;
-
- default:
- return -1;
- }
-
-#if IOMODE_MARSIO
- snd_eth_hdr = (struct mesa_ethernet_hdr *)snd_handle->send_buf;
- memcpy(snd_eth_hdr->ether_shost, raw_eth_hdr->ether_dhost, ETHER_ADDR_LEN);
- memcpy(snd_eth_hdr->ether_dhost, raw_eth_hdr->ether_shost, ETHER_ADDR_LEN);
- snd_eth_hdr->ether_type = ntohs(ETHERTYPE_IP);
-
- ///MESA_sendpacket_ethlayer(thread_id, (char *)snd_handle->send_buf, send_len + 14, 0);
-
- marsio_buff_t *send_mbuf[1];
- char *real_buf;
-
- ret = marsio_buff_malloc_global(sapp_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_id);
- if(ret < 0){
- goto err;
- }
- g_SysInputInfo[thread_id][PKT_MARSIO_MALLOC]++;
-
- /* �˴�ʹ��append������mtod, append�ڲ�ʵ�ʰ�����set datalen�IJ��� */
- real_buf = marsio_buff_append(send_mbuf[0], send_len + 14);
-
- memcpy(real_buf, snd_handle->send_buf, send_len + 14); /* send_lenû����mac��ַ */
-
- ret = marsio_send_burst_with_options_for_tcpdumpmesa((struct mr_sendpath *)g_packet_device_alias[0].dl_io_param,
- thread_id, send_mbuf, 1, MARSIO_SEND_OPT_FAST);
- g_SysInputInfo[thread_id][PKT_MARSIO_SND]++;
- /* mbuf ��������Զ��ͷ� */
-#else
- ret = packet_io_send(snd_handle, send_len, SEND_TYPE_LINK_INJECT,
- __ADDR_TYPE_IP_PAIR_V4, dir, thread_id,
- (char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER);
-
-#endif
-
- packet_io_free_sendbuf(SEND_TYPE_LINK_INJECT, thread_id);
- return ret;
-
-err:
- packet_io_free_sendbuf(SEND_TYPE_LINK_INJECT, thread_id);
- return -1;
-}
-
-/* �ڴ���UDP����, ����ʶ����Щ������BFD����� */
-static inline int gdev_bfd_pkt_identify(const struct streaminfo *a_udp)
-{
- if(g_topology_mode != NET_CONN_SERIAL_GDEV){ /* ��G����ģʽ */
- return 0;
- }
-
- if((sendto_gdev_card_ip != a_udp->addr.tuple4_v4->daddr)
- && (sendto_gdev_card_ip != a_udp->addr.tuple4_v4->saddr)){
- return 0;
- }
-
- if(BFD_DEFAULT_PORT != ntohs(a_udp->addr.tuple4_v4->dest)){
- return 0;
- }
-
- if(ADDR_TYPE_IPV4 != a_udp->addr.addrtype){ /* Ŀǰ������IPv4 */
- return 0;
- }
-
- if(a_udp->pudpdetail->datalen != (int)sizeof(bfd_header_t)){
- return 0;
- }
-
- return 1;
-}
-
-
-char gdev_keepalive_udp_entry(const struct streaminfo *a_udp, void **pme, int thread_seq, const void *ip_hdr)
-{
- int entry_ret = APP_STATE_GIVEME;
- int kp_ret;
- const struct streaminfo_private *a_udp_pr;
-
- if(OP_STATE_PENDING == a_udp->opstate){
- if(0 == gdev_bfd_pkt_identify(a_udp)){
- return APP_STATE_DROPME;
- }
- }else if(OP_STATE_CLOSE == a_udp->opstate){
- return APP_STATE_DROPME;
- }
-
- a_udp_pr = (const struct streaminfo_private *)a_udp;
- kp_ret = gdev_keepalive_plug(a_udp_pr->raw_pkt, a_udp->threadnum, a_udp->routedir, GDEV_KEEPALIVE_TYPE_BFD);
- if(kp_ret < 0){
- entry_ret = APP_STATE_GIVEME; /* ������, socket�ȴ����ܷ���APP_STATE_DROPME, ����DROP ME����Ҳ�ò������������ */
- }else{
- entry_ret = APP_STATE_GIVEME | APP_STATE_DROPPKT; /* �����, ������ǰ�� */
- }
-
- return entry_ret;
-}
-
-
-char gdev_keepalive_ip_entry(const struct streaminfo *pstream,unsigned char routedir,int thread_seq, const struct mesa_ip4_hdr *ipv4_hdr)
-{
- const struct mesa_icmp_echo_hdr *icmp_hdr;
- const struct streaminfo_private *pstream_pr;
- int entry_ret = APP_STATE_GIVEME;
- int kp_ret;
-
- if(ipv4_hdr->ip_p != IPPROTO_ICMP){
- return APP_STATE_DROPME;
- }
-
- if(ipv4_hdr->ip_dst.s_addr != sendto_gdev_card_ip){
- return APP_STATE_DROPME;
- }
-
- icmp_hdr = (struct mesa_icmp_echo_hdr *)((char *)ipv4_hdr + ipv4_hdr->ip_hl*4);
- if(icmp_hdr->icmp_type != ICMP_ECHO){
- return APP_STATE_DROPME;
- }
-
- pstream_pr = (const struct streaminfo_private *)pstream;
- kp_ret = gdev_keepalive_plug(pstream_pr->raw_pkt, thread_seq, pstream->routedir, GDEV_KEEPALIVE_TYPE_ICMP);
- if(kp_ret < 0){
- entry_ret = APP_STATE_DROPME;
- }else{
- entry_ret = APP_STATE_GIVEME | APP_STATE_DROPPKT; /* �����, ������ǰ�� */
- }
-
- return entry_ret;
-}
-
-
-static long _gdev_keepalive_rcv_pps;
-static long _gdev_keepalive_snd_pps;
-
-static void __gdev_keepalive_pkt_calc_pps(void)
-{
- static long _last_rcv_num, _last_snd_num;
- long rcv_sum = 0;
- long snd_sum = 0;
- int tid, log_num;
-
- for(tid = 0; tid < g_packet_io_thread_num; tid++){
- for(log_num = 0; log_num < MAX_GDEV_STAT_LOG_NUM; log_num++){
- rcv_sum += GDEV_KEEPALIVE_STAT[tid][log_num].tot_rcv_pkt_num;
- snd_sum += GDEV_KEEPALIVE_STAT[tid][log_num].tot_snd_pkt_num;
- }
- }
-
- _gdev_keepalive_rcv_pps = rcv_sum - _last_rcv_num;
- _gdev_keepalive_snd_pps = snd_sum - _last_snd_num;
-
- _last_rcv_num = rcv_sum;
- _last_snd_num = snd_sum;
-
- return;
-}
-
-static void *gdev_keepalive_log_thread(void *arg)
-{
- FILE *gdev_status_fp;
- int index, thread_seq;
- int platform_thread_num;
- char cur_time_str[64];
- char tmp_ip_str[32];
- const char *tmp_keealive_type;
- time_t last_op_time;
-
- last_op_time = time(NULL);
-
- while(1){
- gdev_status_fp = fopen("log/gdev_keeplive_status.log", "w+");
- if(NULL == gdev_status_fp){
- sleep(1);
- continue;
- }
- platform_thread_num = get_thread_count();
- timet_to_str(g_CurrentTime, cur_time_str, 64);
- fprintf(gdev_status_fp, "%-20s %-16s %-11s %-5s %-5s %-16s %-16s\n",
- "Last-update-time", "Gdev-ip", "Service-Num", "Ctrl", "Type", "Rcv-pkt", "Snd-pkt");
-
- for(thread_seq = 0; thread_seq < platform_thread_num; thread_seq++)
- {
- for(index = 0; index < MAX_GDEV_STAT_LOG_NUM; index++){
- if(0 == GDEV_KEEPALIVE_STAT[thread_seq][index].active_flag){
- continue;
- }
- inet_ntop(AF_INET, &GDEV_KEEPALIVE_STAT[thread_seq][index].gdev_ip_network_order, tmp_ip_str, 32);
- if(GDEV_KEEPALIVE_TYPE_ICMP == GDEV_KEEPALIVE_STAT[thread_seq][index].gdev_keepalive_type){
- tmp_keealive_type = "ICMP";
- }else if(GDEV_KEEPALIVE_TYPE_BFD == GDEV_KEEPALIVE_STAT[thread_seq][index].gdev_keepalive_type){
- tmp_keealive_type = "BFD";
- }else{
- tmp_keealive_type = "Unknown";
- }
-
- fprintf(gdev_status_fp, "%-20s %-16s %-11d %-5d %-5s %-16u %-16u\n",
- cur_time_str,
- tmp_ip_str,
- GDEV_KEEPALIVE_STAT[thread_seq][index].gdev_keepalive_service_num,
- gdev_kp_action_judge(GDEV_KEEPALIVE_STAT[thread_seq][index].gdev_keepalive_service_num),
- tmp_keealive_type,
- GDEV_KEEPALIVE_STAT[thread_seq][index].tot_rcv_pkt_num,
- GDEV_KEEPALIVE_STAT[thread_seq][index].tot_snd_pkt_num);
- }
- }
-
- __gdev_keepalive_pkt_calc_pps();
-
- fclose(gdev_status_fp);
-
- while(last_op_time == time(NULL)){
- usleep(100);
- }
- last_op_time = time(NULL);
- }
-
- return NULL;
-}
-
-
-int gdev_keepalive_plug_init(void)
-{
- char tmp_ip_buf[16];
- int i;
-
- assert(sizeof(gdev_keepalive_status_t) % 64 == 0);
-
- gdev_kp_log_handle = MESA_create_runtime_log_handle("./log/gdev_keeplive.log", 0);
-
- if(g_topology_mode != NET_CONN_SERIAL_GDEV){ /* ��G����ģʽ */
- MESA_handle_runtime_log(gdev_kp_log_handle, 30, "[gdev_keepalive]",
- "In non-gdev mode, can't load gdev_keepalive.so\n");
- return -1;
- }
-
- memset(tmp_ip_buf, 0, 16);
- MESA_load_profile_string_nodef((char *)"conf/gdev.conf", (char *)"Module", (char *)"sendto_gdev_ip", tmp_ip_buf, 16);
- if(tmp_ip_buf[0] == '\0'){
- MESA_handle_runtime_log(gdev_kp_log_handle, 30, "[gdev_keepalive]","can't get 'sendto_gdev_ip'");
- return -1;
- }
-
- inet_pton(AF_INET, tmp_ip_buf, &sendto_gdev_card_ip);
-
- MESA_load_profile_int_def((char *)"conf/gdev.conf", (char *)"Module", (char *)"default_keepalive_action", &g_dev_keepalive_default_action, 1);
- MESA_load_profile_int_def((char *)"conf/gdev.conf", (char *)"Module", (char *)"gdev_status_switch", &GDEV_KEEPALIVE_LOG_SWITCH, 1);
-
- vxlan_sport_service_map_init();
-
- for(i = 0; i < MAX_VXLAN_SERVICE_NUM; i++){
- g_dev_keepalive_service_ctrl_array[i].service_num = i;
- g_dev_keepalive_service_ctrl_array[i].keepalive_switch = g_dev_keepalive_default_action;
- }
-
- if(GDEV_KEEPALIVE_LOG_SWITCH){
- pthread_t log_pid;
- pthread_create(&log_pid, NULL, gdev_keepalive_log_thread, NULL);
- }
-
- return 0;
-}
-
-
-static int gdev_kp_update_service_ctrl(const struct gdev_keepalive_service_ctrl *service_ctrl)
-{
- if((service_ctrl->service_num < 0) || (service_ctrl->service_num >= MAX_VXLAN_SERVICE_NUM)){
- return -1;
- }
-
- g_dev_keepalive_service_ctrl_array[service_ctrl->service_num].keepalive_switch = service_ctrl->keepalive_switch;
-
- return 0;
-}
-
-int gdev_keepalive_set_opt(const SAPP_TLV_T *tlv_value)
-{
- int ret = 0;
- static time_t last_log_time = 0;
-
- if((NULL == tlv_value) || (tlv_value->length <= 0)){
- return -1;
- }
-
- switch(tlv_value->type){
- case GDEV_KEEPALIVE_OPT_SERVICE_CTRL:
- {
- if(tlv_value->length != sizeof(struct gdev_keepalive_service_ctrl)){
- return -1;
- }
- const struct gdev_keepalive_service_ctrl *actual_val = (const struct gdev_keepalive_service_ctrl *)tlv_value->ptr_value;
-
- ret = gdev_kp_update_service_ctrl(actual_val);
- if(ret < 0){
- if(last_log_time < g_CurrentTime){
- last_log_time = g_CurrentTime;
- MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "set gdev-keepalive error! service:%d, action:%d",
- actual_val->service_num, actual_val->keepalive_switch);
- }
- }else{
- if(last_log_time < g_CurrentTime){
- last_log_time = g_CurrentTime;
- MESA_handle_runtime_log(gdev_kp_log_handle, 10, "[gdev_keepalive]", "set gdev-keepalive, service:%d, action:%d",
- actual_val->service_num, actual_val->keepalive_switch);
- }
- }
- }
- break;
-
- case GDEV_KEEPALIVE_OPT_GLOBAL_SWITCH:
- {
- if(tlv_value->length != sizeof(int)){
- return -1;
- }
- g_dev_keepalive_flag = tlv_value->int_value;
- if(last_log_time < g_CurrentTime){
- MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "set global keepalive to %d", tlv_value->int_value);
- last_log_time = g_CurrentTime;
- }
- }
- break;
-
- default:
- ret = -2;
- break;
- }
-
- return ret;
-}
-
-int gdev_keepalive_get_opt(SAPP_TLV_T *tlv_value)
-{
- int ret = 0;
-
- if((NULL == tlv_value) || (tlv_value->length <= 0)){
- return -1;
- }
-
- switch(tlv_value->type){
-
- case GDEV_KEEPALIVE_OPT_GLOBAL_SWITCH:
- {
- tlv_value->int_value = g_dev_keepalive_flag;
- }
- break;
-
- case GDEV_KEEPALIVE_OPT_RCV_PKT_PPS:
- {
- tlv_value->long_value = _gdev_keepalive_rcv_pps;
- }
- break;
-
- case GDEV_KEEPALIVE_OPT_SND_PKT_PPS:
- {
- tlv_value->long_value = _gdev_keepalive_snd_pps;
- }
- break;
-
- default:
- ret = -1;
- break;
- }
-
- return ret;
-}
-
-/* vxlan���⻷����, vpn-id, Դ�˿ں�ҵ��ID֮��Ĺ�ϵ, �����ļ���ʽ:
-
- service-id VPN-id Sport-range
- 1 101 50000-50016
- 2 102 50064-50080
- ......
-
- ���ڸ�֪�ϲ�Ӧ��ҵ���, �ʹ�������ҵ���Ƿ���Ҫ����.
-*/
-
-static unsigned char g_vxlan_sport_to_service_id[65536]; /* �����±�ΪԴ�˿�, ֵΪservice-id */
-
-
-static int vxlan_sport_service_map_update(int service_id, unsigned short begin_sport_host, unsigned short end_sport_host)
-{
- unsigned short i;
-
- for(i = begin_sport_host; i <= end_sport_host;i++){
- g_vxlan_sport_to_service_id[i] = service_id;
- }
-
- return 0;
-}
-
-static int vxlan_sport_service_map_init(void)
-{
- char line_buf[1024];
- FILE *fp;
- int tmp_service_id, tmp_int;
- const char *delim = "\t- ";
- char *save_ptr;
- char *section;
- unsigned short begin_sport, end_sport;
-
- fp = fopen(VXLAN_SPORT_SERVICE_MAP_FILE, "r");
- if(NULL == fp){
- MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "open file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
- return -1;
- }
-
- while(fgets(line_buf, 1024, fp) != NULL){
- if('#' == line_buf[0]){
- continue;
- }
- del_last_rn(line_buf, 1024);
-
- /* service-id */
- section = strtok_r(line_buf, delim, &save_ptr);
- if(NULL == section){
- MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "parse file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
- goto done;
- }
- tmp_service_id = atoi(section);
-
- /* VPN-id, ��ʱ����ת��, ֱ�Ӽ�100����ҵ��� */
- section = strtok_r(NULL, delim, &save_ptr);
- if(NULL == section){
- MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "parse file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
- goto done;
- }
-
- /* begin-port */
- section = strtok_r(NULL, delim, &save_ptr);
- if(NULL == section){
- MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "parse file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
- goto done;
- }
- tmp_int = atoi(section);
- if(tmp_int <= 0 || tmp_int > 65535){
- MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "parse file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
- goto done;
- }
- begin_sport = (unsigned short)tmp_int;
-
- /* end-port */
- section = strtok_r(NULL, delim, &save_ptr);
- if(NULL == section){
- MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "parse file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
- goto done;
- }
- tmp_int = atoi(section);
- if(tmp_int <= 0 || tmp_int > 65535){
- MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "parse file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
- goto done;
- }
- end_sport = (unsigned short)tmp_int;
-
- if(end_sport < begin_sport){
- MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "parse file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
- goto done;
- }
-
- while(strtok_r(NULL, delim, &save_ptr));
-
- vxlan_sport_service_map_update(tmp_service_id, begin_sport, end_sport);
- }
-
-done:
- fclose(fp);
-
- return 0;
-}
-
-unsigned char vxlan_sport_map_to_service_id(unsigned short sport_host_order)
-{
- return g_vxlan_sport_to_service_id[sport_host_order];
-}
-
-unsigned char vxlan_id_map_to_service_id(int vxlan_id)
-{
- return (unsigned char)(vxlan_id - 100);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ ��wangyanƽ̨��������, �Ƿ���GDEV�����Ǹ��ݲ��������״̬��̬����, �������ٹ̶�һֱ����,
+
+ ���Խ�GDEV-KEEPALIVE���ܴ�ƽ̨�а���,
+ ���ص�IP��UDP�������ԭ�б����.
+
+ Ŀǰû��arp_entry, ethernet_entry, ARP�ظ�������ʱ������ƽ̨�ڲ�.
+*/
+
+#include <pthread.h>
+#ifndef __FAVOR_BSD
+#define __FAVOR_BSD 1
+#endif
+
+#include <arpa/inet.h>
+#include <netinet/udp.h>
+#include <stdlib.h>
+#include "stream_internal.h"
+#include "stream_manage.h"
+#include "logger.h"
+#include "packet_io.h"
+#include "g_device.h"
+#include "mesa_net.h"
+#include "packet_io_internal.h"
+#include "sendpacket.h"
+#include "deal_ipv4.h"
+#include "MESA_prof_load.h"
+#include "MESA_handle_logger.h"
+#include "gdev_keepalive.h"
+#include "stream_rawpkt.h"
+
+#if IOMODE_MARSIO
+#include "marsio.h"
+extern struct mr_instance * sapp_marsio4_instance;
+extern int marsio_send_burst_with_options_for_tcpdumpmesa(struct mr_sendpath * sendpath, queue_id_t sid, marsio_buff_t * mbufs[], int nr_mbufs, uint16_t options);
+
+#endif
+
+int gdev_keepalive_plug_version_VERSION_20180305;
+
+#define MAX_GDEV_STAT_LOG_NUM (64)
+
+static void *gdev_kp_log_handle;
+enum prog_work_mode_t{
+ PROG_MODE_MASTER = 1,
+ PROG_MODE_SLAVE = 2,
+};
+
+typedef struct {
+ int active_flag; /* ��IP���� */
+ int gdev_keepalive_type;
+ int gdev_keepalive_service_num; /* BFD��ȡ */
+ unsigned int gdev_ip_network_order;
+ unsigned int tot_rcv_pkt_num;
+ unsigned int tot_snd_pkt_num;
+ time_t last_time;
+ char __pad__[32]; /* 64byte cache aligned */
+}gdev_keepalive_status_t;
+
+static gdev_keepalive_status_t GDEV_KEEPALIVE_STAT[MAX_THREAD_NUM][MAX_GDEV_STAT_LOG_NUM];
+
+static int g_dev_keepalive_flag = 1; /* ȫ�ֱ����־, ���в���������������Ҫ������������ */
+
+#define MAX_VXLAN_SERVICE_NUM (256) /* Ŀǰ���֧��255�ֲ�ͬҵ�� */
+static struct gdev_keepalive_service_ctrl g_dev_keepalive_service_ctrl_array[MAX_VXLAN_SERVICE_NUM];/* ����ij��ҵ����Ƿ񱣻� */
+#define VXLAN_SPORT_SERVICE_MAP_FILE "./conf/vxlan_sport_service_map.conf"
+
+static int GDEV_KEEPALIVE_LOG_SWITCH = 1;
+
+extern int g_packet_io_thread_num;
+extern time_t g_CurrentTime;
+static int g_dev_keepalive_default_action = 1; /* ����g_dev_keepalive_service_ctrl_array��û�е�ҵ���, �DZ���Dz����� */
+static unsigned int sendto_gdev_card_ip; /* ��Gdev����������IP��ַ, ������, network-order */
+extern int g_topology_mode;
+extern int sendpacket_build_icmpv4_echo(u_int8_t type, u_int8_t code, u_int16_t sum,
+ u_int16_t id, u_int16_t seq, u_int8_t *payload, u_int32_t payload_s, unsigned char *buf);
+extern char *timet_to_str(time_t timet, char *time_str, int time_str_len);
+static int vxlan_sport_service_map_init(void);
+extern void del_last_rn(char *data, int max_len);
+
+static unsigned char g_vxlan_sport_to_service_id[65536]; /* �����±�ΪԴ�˿�, ֵΪservice-id */
+
+
+static int gdev_kp_action_judge(int service_id)
+{
+ if(0 == g_dev_keepalive_flag){
+ return 0;
+ }
+
+ return g_dev_keepalive_service_ctrl_array[service_id].keepalive_switch;
+}
+
+
+static void gdev_keepalive_stat_update(int tid, unsigned int gip_net, int type, int service_id, int action)
+{
+ int index;
+
+ for(index = 0; index < MAX_GDEV_STAT_LOG_NUM; index++){
+ if(0 == GDEV_KEEPALIVE_STAT[tid][index].active_flag){
+ break;
+ }
+ if((gip_net == GDEV_KEEPALIVE_STAT[tid][index].gdev_ip_network_order)
+ &&(service_id == GDEV_KEEPALIVE_STAT[tid][index].gdev_keepalive_service_num)
+ && (type == GDEV_KEEPALIVE_STAT[tid][index].gdev_keepalive_type)){
+ GDEV_KEEPALIVE_STAT[tid][index].last_time = g_CurrentTime;
+ GDEV_KEEPALIVE_STAT[tid][index].tot_rcv_pkt_num++;
+ GDEV_KEEPALIVE_STAT[tid][index].tot_snd_pkt_num += action;
+ return;
+ }
+ }
+
+ /* not found, check number */
+ if(index >= MAX_GDEV_STAT_LOG_NUM){
+ MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]",
+ "Too many gdev ip, moren than %d!\n",
+ MAX_GDEV_STAT_LOG_NUM);
+ return;
+ }
+
+ GDEV_KEEPALIVE_STAT[tid][index].active_flag = 1;
+ GDEV_KEEPALIVE_STAT[tid][index].gdev_keepalive_type = type;
+ GDEV_KEEPALIVE_STAT[tid][index].gdev_keepalive_service_num = service_id;
+ GDEV_KEEPALIVE_STAT[tid][index].gdev_ip_network_order = gip_net;
+ GDEV_KEEPALIVE_STAT[tid][index].tot_rcv_pkt_num = 1;
+ GDEV_KEEPALIVE_STAT[tid][index].tot_snd_pkt_num = action;
+ GDEV_KEEPALIVE_STAT[tid][index].last_time = g_CurrentTime;
+ return;
+}
+
+/* �����豸�������BFDЭ�� */
+static int gdev_keepalive_bfd_plug(const raw_pkt_t *raw_pkt, int thread_id, unsigned char dir, unsigned char *send_buf)
+{
+ char payload_buf[1472];
+ struct mesa_ethernet_hdr *eth_hdr = (struct mesa_ethernet_hdr *)raw_pkt->raw_pkt_data;
+ struct mesa_ip4_hdr *ip_hdr = (struct mesa_ip4_hdr *)((char *)eth_hdr+ SENDPACKET_ETH_H);
+ struct mesa_udp_hdr *udp_hdr = (struct mesa_udp_hdr *)((char *)eth_hdr + SENDPACKET_ETH_H + ip_hdr->ip_hl*4);
+ bfd_header_t *bfd_net_hdr = (bfd_header_t *)((char *)eth_hdr + SENDPACKET_ETH_H + ip_hdr->ip_hl*4 + SENDPACKET_UDP_H);
+ bfd_header_t *bfd_send_hdr = (bfd_header_t *)payload_buf;
+ char bfd_buf[4];
+ int payload_len = ntohs(udp_hdr->uh_ulen) - SENDPACKET_UDP_H;
+ int service_id = 0;
+ int action;
+
+#if 0 /* ��ΪUDP���, ��gdev_bfd_pkt_identify�Ѿ��жϹ�, �����ٴ��ж� */
+ if(ntohs(eth_hdr->ether_type) != ETHERTYPE_IP){
+ return -1;
+ }
+
+ if(ip_hdr->ip_p != IPPROTO_UDP){
+ return -1;
+ }
+
+ if(ntohs(udp_hdr->uh_dport) != BFD_DEFAULT_PORT){
+ return -1;
+ }
+
+ if(memcmp(&ip_hdr->ip_dst.s_addr, &sendto_gdev_card_ip, sizeof(int)) != 0){
+ return -1;
+ }
+
+ if(payload_len != (int)sizeof(bfd_header_t)){
+ return -1;
+ }
+#endif
+
+ service_id = vxlan_sport_map_to_service_id(ntohs(udp_hdr->uh_sport));
+ action = gdev_kp_action_judge(service_id);
+
+ gdev_keepalive_stat_update(thread_id, ip_hdr->ip_src.s_addr, GDEV_KEEPALIVE_TYPE_BFD, service_id, action);
+
+ if(0 == action){
+ return -1;
+ }
+ /* ��ȡ����service_id, ����Ӧ�ûظ�����Ӧ��, go on !! */
+
+ memcpy(payload_buf, bfd_net_hdr, payload_len);
+
+ memcpy(bfd_buf, bfd_send_hdr->my_discriminator, 4);
+ memcpy(bfd_send_hdr->my_discriminator, bfd_send_hdr->your_discriminator, 4);
+ memcpy(bfd_send_hdr->your_discriminator, bfd_buf, 4);
+
+ sendpacket_build_udp_dual_stack(ntohs(udp_hdr->uh_sport), /* BFDЭ�鲻����Դ��Ŀ�Ķ˿� */
+ ntohs(udp_hdr->uh_dport),
+ (char *)bfd_send_hdr,
+ payload_len,
+ payload_len,
+ send_buf + SENDPACKET_ETH_H + SENDPACKET_IP_H);
+
+ sendpacket_build_ipv4(SENDPACKET_UDP_H + payload_len,
+ 0,
+ ntohs(ip_hdr->ip_id),
+ ntohs(ip_hdr->ip_off),
+ ip_hdr->ip_ttl,
+ IPPROTO_UDP,
+ ip_hdr->ip_dst.s_addr,
+ ip_hdr->ip_src.s_addr, /* ����Դ��Ŀ��IP��ַ */
+ NULL, 0,
+ send_buf + SENDPACKET_ETH_H);
+
+ sendpacket_do_checksum(send_buf + SENDPACKET_ETH_H,
+ IPPROTO_IP,
+ SENDPACKET_IP_H);
+
+ sendpacket_do_checksum(send_buf + SENDPACKET_ETH_H,
+ IPPROTO_UDP,
+ payload_len + SENDPACKET_UDP_H);
+
+
+ return SENDPACKET_IP_H + SENDPACKET_UDP_H+sizeof(bfd_header_t);
+}
+
+/* �����豸�������BFDЭ�� */
+static int gdev_keepalive_icmp_plug(const raw_pkt_t *raw_pkt, int thread_id, unsigned char dir, unsigned char *send_buf)
+{
+ struct mesa_ethernet_hdr *eth_hdr = (struct mesa_ethernet_hdr *)raw_pkt->raw_pkt_data;
+ struct mesa_ip4_hdr *ip_hdr = (struct mesa_ip4_hdr *)((char *)eth_hdr + SENDPACKET_ETH_H);
+ struct mesa_icmp_echo_hdr *icmp_hdr = (struct mesa_icmp_echo_hdr *)((char *)eth_hdr + SENDPACKET_ETH_H + ip_hdr->ip_hl*4);
+ unsigned char *icmp_payload;
+ int icmp_payload_len;
+
+ gdev_keepalive_stat_update(thread_id, ip_hdr->ip_src.s_addr, GDEV_KEEPALIVE_TYPE_ICMP, 0, g_dev_keepalive_default_action);
+
+ icmp_payload = (unsigned char *)icmp_hdr + sizeof(struct mesa_icmp_echo_hdr);
+ icmp_payload_len = ntohs(ip_hdr->ip_len) - ip_hdr->ip_hl*4 - sizeof(struct mesa_icmp_echo_hdr);
+
+
+ sendpacket_build_icmpv4_echo(ICMP_ECHOREPLY, 0, 0,
+ ntohs(icmp_hdr->icd_id),
+ ntohs(icmp_hdr->icd_seq),
+ icmp_payload,
+ icmp_payload_len,
+ send_buf + SENDPACKET_ETH_H + SENDPACKET_IP_H);
+
+ sendpacket_build_ipv4(icmp_payload_len + sizeof(struct mesa_icmp_echo_hdr),
+ 0, 0x1234, 0, 64, IPPROTO_ICMP,
+ ip_hdr->ip_dst.s_addr,
+ ip_hdr->ip_src.s_addr,
+ NULL, 0,
+ send_buf + SENDPACKET_ETH_H);
+ memcpy(send_buf + SENDPACKET_ETH_H+SENDPACKET_IP_H+sizeof(struct mesa_icmp_echo_hdr),
+ icmp_payload,
+ icmp_payload_len);
+
+
+ sendpacket_do_checksum(send_buf + SENDPACKET_ETH_H,
+ IPPROTO_IP,
+ SENDPACKET_IP_H);
+
+ sendpacket_do_checksum(send_buf + SENDPACKET_ETH_H,
+ IPPROTO_ICMP,
+ icmp_payload_len + sizeof(struct mesa_icmp_echo_hdr));
+
+ return ntohs(ip_hdr->ip_len);
+}
+
+
+static int gdev_keepalive_plug(const raw_pkt_t *raw_pkt, int thread_id, unsigned char dir, int keepalive_type)
+{
+ int ret = -1, send_len;
+ MESA_send_handle *snd_handle = NULL;
+#if IOMODE_MARSIO
+ const struct mesa_ethernet_hdr *raw_eth_hdr = (struct mesa_ethernet_hdr *)raw_pkt->raw_pkt_data;
+ struct mesa_ethernet_hdr *snd_eth_hdr;
+#endif
+
+ snd_handle = packet_io_get_send_handle(thread_id);
+ if(NULL == snd_handle){
+ return -1;
+ }
+ snd_handle->send_buf = packet_io_get_sendbuf(SEND_TYPE_LINK_INJECT, thread_id);
+ if(NULL == snd_handle->send_buf){
+ return 0;
+ }
+
+ switch(keepalive_type){
+ case GDEV_KEEPALIVE_TYPE_BFD:
+ send_len = gdev_keepalive_bfd_plug(raw_pkt, thread_id, dir, snd_handle->send_buf);
+ if(send_len < 0){
+ goto err;
+ }
+ break;
+
+ case GDEV_KEEPALIVE_TYPE_ICMP:
+ send_len = gdev_keepalive_icmp_plug(raw_pkt, thread_id, dir, snd_handle->send_buf);
+ if(send_len < 0){
+ goto err;
+ }
+ break;
+
+ default:
+ return -1;
+ }
+
+#if IOMODE_MARSIO
+ snd_eth_hdr = (struct mesa_ethernet_hdr *)snd_handle->send_buf;
+ memcpy(snd_eth_hdr->ether_shost, raw_eth_hdr->ether_dhost, ETHER_ADDR_LEN);
+ memcpy(snd_eth_hdr->ether_dhost, raw_eth_hdr->ether_shost, ETHER_ADDR_LEN);
+ snd_eth_hdr->ether_type = ntohs(ETHERTYPE_IP);
+
+ ///MESA_sendpacket_ethlayer(thread_id, (char *)snd_handle->send_buf, send_len + 14, 0);
+
+ marsio_buff_t *send_mbuf[1];
+ char *real_buf;
+
+ ret = marsio_buff_malloc_global(sapp_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_id);
+ if(ret < 0){
+ goto err;
+ }
+ g_SysInputInfo[thread_id][PKT_MARSIO_MALLOC]++;
+
+ /* �˴�ʹ��append������mtod, append�ڲ�ʵ�ʰ�����set datalen�IJ��� */
+ real_buf = marsio_buff_append(send_mbuf[0], send_len + 14);
+
+ memcpy(real_buf, snd_handle->send_buf, send_len + 14); /* send_lenû����mac��ַ */
+
+ ret = marsio_send_burst_with_options_for_tcpdumpmesa((struct mr_sendpath *)g_packet_device_alias[0].dl_io_param,
+ thread_id, send_mbuf, 1, MARSIO_SEND_OPT_FAST);
+ g_SysInputInfo[thread_id][PKT_MARSIO_SND]++;
+ /* mbuf ��������Զ��ͷ� */
+#else
+ ret = packet_io_send(snd_handle, send_len, SEND_TYPE_LINK_INJECT,
+ __ADDR_TYPE_IP_PAIR_V4, dir, thread_id,
+ (char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER);
+
+#endif
+
+ packet_io_free_sendbuf(SEND_TYPE_LINK_INJECT, thread_id);
+ return ret;
+
+err:
+ packet_io_free_sendbuf(SEND_TYPE_LINK_INJECT, thread_id);
+ return -1;
+}
+
+/* �ڴ���UDP����, ����ʶ����Щ������BFD����� */
+static inline int gdev_bfd_pkt_identify(const struct streaminfo *a_udp)
+{
+ if(g_topology_mode != NET_CONN_SERIAL_GDEV){ /* ��G����ģʽ */
+ return 0;
+ }
+
+ if((sendto_gdev_card_ip != a_udp->addr.tuple4_v4->daddr)
+ && (sendto_gdev_card_ip != a_udp->addr.tuple4_v4->saddr)){
+ return 0;
+ }
+
+ if(BFD_DEFAULT_PORT != ntohs(a_udp->addr.tuple4_v4->dest)){
+ return 0;
+ }
+
+ if(ADDR_TYPE_IPV4 != a_udp->addr.addrtype){ /* Ŀǰ������IPv4 */
+ return 0;
+ }
+
+ if(a_udp->pudpdetail->datalen != (int)sizeof(bfd_header_t)){
+ return 0;
+ }
+
+ return 1;
+}
+
+
+char gdev_keepalive_udp_entry(const struct streaminfo *a_udp, void **pme, int thread_seq, const void *ip_hdr)
+{
+ int entry_ret = APP_STATE_GIVEME;
+ int kp_ret;
+ const struct streaminfo_private *a_udp_pr;
+
+ if(OP_STATE_PENDING == a_udp->opstate){
+ if(0 == gdev_bfd_pkt_identify(a_udp)){
+ return APP_STATE_DROPME;
+ }
+ }else if(OP_STATE_CLOSE == a_udp->opstate){
+ return APP_STATE_DROPME;
+ }
+
+ a_udp_pr = (const struct streaminfo_private *)a_udp;
+ kp_ret = gdev_keepalive_plug(a_udp_pr->raw_pkt, a_udp->threadnum, a_udp->routedir, GDEV_KEEPALIVE_TYPE_BFD);
+ if(kp_ret < 0){
+ entry_ret = APP_STATE_GIVEME; /* ������, socket�ȴ����ܷ���APP_STATE_DROPME, ����DROP ME����Ҳ�ò������������ */
+ }else{
+ entry_ret = APP_STATE_GIVEME | APP_STATE_DROPPKT; /* �����, ������ǰ�� */
+ }
+
+ return entry_ret;
+}
+
+
+char gdev_keepalive_ip_entry(const struct streaminfo *pstream,unsigned char routedir,int thread_seq, const struct mesa_ip4_hdr *ipv4_hdr)
+{
+ const struct mesa_icmp_echo_hdr *icmp_hdr;
+ const struct streaminfo_private *pstream_pr;
+ int entry_ret = APP_STATE_GIVEME;
+ int kp_ret;
+
+ if(ipv4_hdr->ip_p != IPPROTO_ICMP){
+ return APP_STATE_DROPME;
+ }
+
+ if(ipv4_hdr->ip_dst.s_addr != sendto_gdev_card_ip){
+ return APP_STATE_DROPME;
+ }
+
+ icmp_hdr = (struct mesa_icmp_echo_hdr *)((char *)ipv4_hdr + ipv4_hdr->ip_hl*4);
+ if(icmp_hdr->icmp_type != ICMP_ECHO){
+ return APP_STATE_DROPME;
+ }
+
+ pstream_pr = (const struct streaminfo_private *)pstream;
+ kp_ret = gdev_keepalive_plug(pstream_pr->raw_pkt, thread_seq, pstream->routedir, GDEV_KEEPALIVE_TYPE_ICMP);
+ if(kp_ret < 0){
+ entry_ret = APP_STATE_DROPME;
+ }else{
+ entry_ret = APP_STATE_GIVEME | APP_STATE_DROPPKT; /* �����, ������ǰ�� */
+ }
+
+ return entry_ret;
+}
+
+
+static long _gdev_keepalive_rcv_pps;
+static long _gdev_keepalive_snd_pps;
+
+static void __gdev_keepalive_pkt_calc_pps(void)
+{
+ static long _last_rcv_num, _last_snd_num;
+ long rcv_sum = 0;
+ long snd_sum = 0;
+ int tid, log_num;
+
+ for(tid = 0; tid < g_packet_io_thread_num; tid++){
+ for(log_num = 0; log_num < MAX_GDEV_STAT_LOG_NUM; log_num++){
+ rcv_sum += GDEV_KEEPALIVE_STAT[tid][log_num].tot_rcv_pkt_num;
+ snd_sum += GDEV_KEEPALIVE_STAT[tid][log_num].tot_snd_pkt_num;
+ }
+ }
+
+ _gdev_keepalive_rcv_pps = rcv_sum - _last_rcv_num;
+ _gdev_keepalive_snd_pps = snd_sum - _last_snd_num;
+
+ _last_rcv_num = rcv_sum;
+ _last_snd_num = snd_sum;
+
+ return;
+}
+
+static void *gdev_keepalive_log_thread(void *arg)
+{
+ FILE *gdev_status_fp;
+ int index, thread_seq;
+ int platform_thread_num;
+ char cur_time_str[64];
+ char tmp_ip_str[32];
+ const char *tmp_keealive_type;
+ time_t last_op_time;
+
+ last_op_time = time(NULL);
+
+ while(1){
+ gdev_status_fp = fopen("log/gdev_keeplive_status.log", "w+");
+ if(NULL == gdev_status_fp){
+ sleep(1);
+ continue;
+ }
+ platform_thread_num = get_thread_count();
+ timet_to_str(g_CurrentTime, cur_time_str, 64);
+ fprintf(gdev_status_fp, "%-20s %-16s %-11s %-5s %-5s %-16s %-16s\n",
+ "Last-update-time", "Gdev-ip", "Service-Num", "Ctrl", "Type", "Rcv-pkt", "Snd-pkt");
+
+ for(thread_seq = 0; thread_seq < platform_thread_num; thread_seq++)
+ {
+ for(index = 0; index < MAX_GDEV_STAT_LOG_NUM; index++){
+ if(0 == GDEV_KEEPALIVE_STAT[thread_seq][index].active_flag){
+ continue;
+ }
+ inet_ntop(AF_INET, &GDEV_KEEPALIVE_STAT[thread_seq][index].gdev_ip_network_order, tmp_ip_str, 32);
+ if(GDEV_KEEPALIVE_TYPE_ICMP == GDEV_KEEPALIVE_STAT[thread_seq][index].gdev_keepalive_type){
+ tmp_keealive_type = "ICMP";
+ }else if(GDEV_KEEPALIVE_TYPE_BFD == GDEV_KEEPALIVE_STAT[thread_seq][index].gdev_keepalive_type){
+ tmp_keealive_type = "BFD";
+ }else{
+ tmp_keealive_type = "Unknown";
+ }
+
+ fprintf(gdev_status_fp, "%-20s %-16s %-11d %-5d %-5s %-16u %-16u\n",
+ cur_time_str,
+ tmp_ip_str,
+ GDEV_KEEPALIVE_STAT[thread_seq][index].gdev_keepalive_service_num,
+ gdev_kp_action_judge(GDEV_KEEPALIVE_STAT[thread_seq][index].gdev_keepalive_service_num),
+ tmp_keealive_type,
+ GDEV_KEEPALIVE_STAT[thread_seq][index].tot_rcv_pkt_num,
+ GDEV_KEEPALIVE_STAT[thread_seq][index].tot_snd_pkt_num);
+ }
+ }
+
+ __gdev_keepalive_pkt_calc_pps();
+
+ fclose(gdev_status_fp);
+
+ while(last_op_time == time(NULL)){
+ usleep(100);
+ }
+ last_op_time = time(NULL);
+ }
+
+ return NULL;
+}
+
+
+int gdev_keepalive_plug_init(void)
+{
+ char tmp_ip_buf[16];
+ int i;
+
+ assert(sizeof(gdev_keepalive_status_t) % 64 == 0);
+
+ gdev_kp_log_handle = MESA_create_runtime_log_handle("./log/gdev_keeplive.log", 0);
+
+ if(g_topology_mode != NET_CONN_SERIAL_GDEV){ /* ��G����ģʽ */
+ MESA_handle_runtime_log(gdev_kp_log_handle, 30, "[gdev_keepalive]",
+ "In non-gdev mode, can't load gdev_keepalive.so\n");
+ return -1;
+ }
+
+ memset(g_vxlan_sport_to_service_id, 0, sizeof(g_vxlan_sport_to_service_id));
+
+ memset(tmp_ip_buf, 0, 16);
+ MESA_load_profile_string_nodef((char *)"conf/gdev.conf", (char *)"Module", (char *)"sendto_gdev_ip", tmp_ip_buf, 16);
+ if(tmp_ip_buf[0] == '\0'){
+ MESA_handle_runtime_log(gdev_kp_log_handle, 30, "[gdev_keepalive]","can't get 'sendto_gdev_ip'");
+ return -1;
+ }
+
+ inet_pton(AF_INET, tmp_ip_buf, &sendto_gdev_card_ip);
+
+ MESA_load_profile_int_def((char *)"conf/gdev.conf", (char *)"Module", (char *)"default_keepalive_action", &g_dev_keepalive_default_action, 1);
+ MESA_load_profile_int_def((char *)"conf/gdev.conf", (char *)"Module", (char *)"gdev_status_switch", &GDEV_KEEPALIVE_LOG_SWITCH, 1);
+
+
+ for(i = 0; i < MAX_VXLAN_SERVICE_NUM; i++){
+ g_dev_keepalive_service_ctrl_array[i].service_num = i;
+ g_dev_keepalive_service_ctrl_array[i].keepalive_switch = g_dev_keepalive_default_action;
+ }
+
+ vxlan_sport_service_map_init();
+
+ if(GDEV_KEEPALIVE_LOG_SWITCH){
+ pthread_t log_pid;
+ pthread_create(&log_pid, NULL, gdev_keepalive_log_thread, NULL);
+ }
+
+ return 0;
+}
+
+
+static int gdev_kp_update_service_ctrl(const struct gdev_keepalive_service_ctrl *service_ctrl)
+{
+ if((service_ctrl->service_num < 0) || (service_ctrl->service_num >= MAX_VXLAN_SERVICE_NUM)){
+ return -1;
+ }
+
+ g_dev_keepalive_service_ctrl_array[service_ctrl->service_num].keepalive_switch = service_ctrl->keepalive_switch;
+
+ return 0;
+}
+
+int gdev_keepalive_set_opt(const SAPP_TLV_T *tlv_value)
+{
+ int ret = 0;
+ static time_t last_log_time = 0;
+
+ if((NULL == tlv_value) || (tlv_value->length <= 0)){
+ return -1;
+ }
+
+ switch(tlv_value->type){
+ case GDEV_KEEPALIVE_OPT_SERVICE_CTRL:
+ {
+ if(tlv_value->length != sizeof(struct gdev_keepalive_service_ctrl)){
+ return -1;
+ }
+ const struct gdev_keepalive_service_ctrl *actual_val = (const struct gdev_keepalive_service_ctrl *)tlv_value->ptr_value;
+
+ ret = gdev_kp_update_service_ctrl(actual_val);
+ if(ret < 0){
+ if(last_log_time < g_CurrentTime){
+ last_log_time = g_CurrentTime;
+ MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "set gdev-keepalive error! service:%d, action:%d",
+ actual_val->service_num, actual_val->keepalive_switch);
+ }
+ }else{
+ if(last_log_time < g_CurrentTime){
+ last_log_time = g_CurrentTime;
+ MESA_handle_runtime_log(gdev_kp_log_handle, 10, "[gdev_keepalive]", "set gdev-keepalive, service:%d, action:%d",
+ actual_val->service_num, actual_val->keepalive_switch);
+ }
+ }
+ }
+ break;
+
+ case GDEV_KEEPALIVE_OPT_GLOBAL_SWITCH:
+ {
+ if(tlv_value->length != sizeof(int)){
+ return -1;
+ }
+ g_dev_keepalive_flag = tlv_value->int_value;
+ if(last_log_time < g_CurrentTime){
+ MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "set global keepalive to %d", tlv_value->int_value);
+ last_log_time = g_CurrentTime;
+ }
+ }
+ break;
+
+ default:
+ ret = -2;
+ break;
+ }
+
+ return ret;
+}
+
+int gdev_keepalive_get_opt(SAPP_TLV_T *tlv_value)
+{
+ int ret = 0;
+
+ if((NULL == tlv_value) || (tlv_value->length <= 0)){
+ return -1;
+ }
+
+ switch(tlv_value->type){
+
+ case GDEV_KEEPALIVE_OPT_GLOBAL_SWITCH:
+ {
+ tlv_value->int_value = g_dev_keepalive_flag;
+ }
+ break;
+
+ case GDEV_KEEPALIVE_OPT_RCV_PKT_PPS:
+ {
+ tlv_value->long_value = _gdev_keepalive_rcv_pps;
+ }
+ break;
+
+ case GDEV_KEEPALIVE_OPT_SND_PKT_PPS:
+ {
+ tlv_value->long_value = _gdev_keepalive_snd_pps;
+ }
+ break;
+
+ default:
+ ret = -1;
+ break;
+ }
+
+ return ret;
+}
+
+/* vxlan���⻷����, vpn-id, Դ�˿ں�ҵ��ID֮��Ĺ�ϵ, �����ļ���ʽ:
+
+ service-id VPN-id Sport-range
+ 1 101 50000-50016
+ 2 102 50064-50080
+ ......
+
+ ���ڸ�֪�ϲ�Ӧ��ҵ���, �ʹ�������ҵ���Ƿ���Ҫ����.
+*/
+
+
+static int vxlan_sport_service_map_update(int service_id, unsigned short begin_sport_host, unsigned short end_sport_host)
+{
+ unsigned short i;
+
+ for(i = begin_sport_host; i <= end_sport_host;i++){
+ g_vxlan_sport_to_service_id[i] = service_id;
+ g_dev_keepalive_service_ctrl_array[service_id].keepalive_switch = 1;
+ }
+
+ return 0;
+}
+
+static int vxlan_sport_service_map_init(void)
+{
+ char line_buf[1024];
+ FILE *fp;
+ int tmp_service_id, tmp_int;
+ const char *delim = "\t- ";
+ char *save_ptr;
+ char *section;
+ unsigned short begin_sport, end_sport;
+
+ fp = fopen(VXLAN_SPORT_SERVICE_MAP_FILE, "r");
+ if(NULL == fp){
+ MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "open file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
+ return -1;
+ }
+
+ while(fgets(line_buf, 1024, fp) != NULL){
+ if('#' == line_buf[0]){
+ continue;
+ }
+ del_last_rn(line_buf, 1024);
+
+ /* service-id */
+ section = strtok_r(line_buf, delim, &save_ptr);
+ if(NULL == section){
+ MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "parse file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
+ goto done;
+ }
+ tmp_service_id = atoi(section);
+
+ /* VPN-id, ��ʱ����ת��, ֱ�Ӽ�100����ҵ��� */
+ section = strtok_r(NULL, delim, &save_ptr);
+ if(NULL == section){
+ MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "parse file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
+ goto done;
+ }
+
+ /* begin-port */
+ section = strtok_r(NULL, delim, &save_ptr);
+ if(NULL == section){
+ MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "parse file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
+ goto done;
+ }
+ tmp_int = atoi(section);
+ if(tmp_int <= 0 || tmp_int > 65535){
+ MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "parse file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
+ goto done;
+ }
+ begin_sport = (unsigned short)tmp_int;
+
+ /* end-port */
+ section = strtok_r(NULL, delim, &save_ptr);
+ if(NULL == section){
+ MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "parse file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
+ goto done;
+ }
+ tmp_int = atoi(section);
+ if(tmp_int <= 0 || tmp_int > 65535){
+ MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "parse file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
+ goto done;
+ }
+ end_sport = (unsigned short)tmp_int;
+
+ if(end_sport < begin_sport){
+ MESA_handle_runtime_log(gdev_kp_log_handle, 20, "[gdev_keepalive]", "parse file %s error!\n", VXLAN_SPORT_SERVICE_MAP_FILE);
+ goto done;
+ }
+
+ while(strtok_r(NULL, delim, &save_ptr));
+
+ vxlan_sport_service_map_update(tmp_service_id, begin_sport, end_sport);
+ }
+
+done:
+ fclose(fp);
+
+ return 0;
+}
+
+unsigned char vxlan_sport_map_to_service_id(unsigned short sport_host_order)
+{
+ return g_vxlan_sport_to_service_id[sport_host_order];
+}
+
+unsigned char vxlan_id_map_to_service_id(int vxlan_id)
+{
+ return (unsigned char)(vxlan_id - 100);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/packet_io/CMakeLists.txt b/packet_io/CMakeLists.txt
index 87c4eb8..89e6b6d 100644
--- a/packet_io/CMakeLists.txt
+++ b/packet_io/CMakeLists.txt
@@ -20,6 +20,7 @@ add_definitions(-fPIC)
if(CAPTURE_MODE MATCHES "PCAP")
set(PACKET_IO_SOURCE ${PACKET_IO_SOURCE} packet_io_pcap.c)
add_library(packet_io_pcap SHARED ${PACKET_IO_SOURCE})
+ set_target_properties(packet_io_pcap PROPERTIES PREFIX "")
endif()
if(CAPTURE_MODE MATCHES "PAG")
@@ -47,12 +48,12 @@ endif()
set(PACKET_IO_STATIC_SOURCE cycle_pkt_dump_through_write_offset.c packet_io_lib_load.c pkt_dispatch_new.c
iknow_info.c packet_io_log.c sendpacket.c
sendpacket_wrap.c packet_io.c packet_io_device.c sapp_compat_wangyan_api.c
-#packet_io_status_by_mesafs.cpp packet_io_status.cpp packet_io_status_new.c )
packet_io_status.cpp packet_io_status_new.c )
add_library(packet_io STATIC ${PACKET_IO_STATIC_SOURCE})
+
if(CAPTURE_MODE MATCHES "MARSIO")
target_link_libraries(packet_io marsio)
-endif()
+endif()
target_link_libraries(packet_io timestamp_record iknow)
diff --git a/run/conf/gdev_block.conf b/run/conf/gdev_block.conf
new file mode 100644
index 0000000..dc5c9e2
--- /dev/null
+++ b/run/conf/gdev_block.conf
@@ -0,0 +1,14 @@
+[main]
+nfs_proto_stat_path=./log
+nfs_ddos_flow_detail_path=./log
+
+[gdev]
+service_type=1
+rule_scope=1
+durable=0
+auth_data=B9840E2442951834
+#phony server
+c3_list=10.0.6.201:22;
+
+c3_server_ip=10.0.6.201
+c3_server_port=22
diff --git a/run/conf/send_gdev.conf b/run/conf/send_gdev.conf
new file mode 100644
index 0000000..54b7a0f
--- /dev/null
+++ b/run/conf/send_gdev.conf
@@ -0,0 +1,2 @@
+3 10.3.127.1
+
diff --git a/run/conf/send_route.conf b/run/conf/send_route.conf
new file mode 100644
index 0000000..eb09686
--- /dev/null
+++ b/run/conf/send_route.conf
@@ -0,0 +1,2 @@
+3 2 00:50:56:f3:59:5c
+
diff --git a/test_so/CMakeLists.txt b/test_so/CMakeLists.txt
new file mode 100644
index 0000000..f341394
--- /dev/null
+++ b/test_so/CMakeLists.txt
@@ -0,0 +1,31 @@
+cmake_minimum_required(VERSION 2.8)
+
+include_directories(${MESA_SDK_PREFIX}/include)
+include_directories(${MESA_SDK_PREFIX}/include/MESA)
+include_directories(${CMAKE_SOURCE_DIR}/packet_io)
+include_directories(${CMAKE_SOURCE_DIR}/inner_plug)
+include_directories(${CMAKE_SOURCE_DIR}/include)
+include_directories(${CMAKE_SOURCE_DIR}/include/net)
+include_directories(${CMAKE_SOURCE_DIR}/include/support)
+include_directories(${CMAKE_SOURCE_DIR}/include/stream_inc)
+include_directories(${CMAKE_SOURCE_DIR}/dealpkt)
+
+if(OPT_IOMODE_MARSIO)
+ include_directories(${MARSIO_SDK_PREFIX}/include)
+endif()
+
+add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H)
+
+add_definitions(-fPIC)
+add_library(test_app_sapp SHARED test_app_sapp.c)
+set_target_properties(test_app_sapp PROPERTIES PREFIX "")
+
+add_library(trace_delay SHARED trace_delay.c)
+set_target_properties(trace_delay PROPERTIES PREFIX "")
+
+add_library(wangyan_demo SHARED wangyan_demo.c)
+set_target_properties(wangyan_demo PROPERTIES PREFIX "")
+
+add_library(test_wangyan SHARED test_wangyan.c)
+set_target_properties(test_wangyan PROPERTIES PREFIX "")
+
diff --git a/test_so/Makefile b/test_so/Makefile
index 242aea8..60c98f2 100644
--- a/test_so/Makefile
+++ b/test_so/Makefile
@@ -43,20 +43,20 @@ trace_delay.so: trace_delay.o
$(CC) -o $@ -shared -fPIC $(CFLAGS) $^ $(MODULES)
cp $@ ../run/plug/business/test_app/
-terminal_tag.so: terminal_tag.o
- $(CC) -o $@ -shared -fPIC $(CFLAGS) $^ $(MODULES)
- cp $@ ../run/plug/business/terminal_tag/
+#terminal_tag.so: terminal_tag.o
+# $(CC) -o $@ -shared -fPIC $(CFLAGS) $^ $(MODULES)
+# cp $@ ../run/plug/business/terminal_tag/
-test_http.so:test_http.o
- $(CC) -o $@ -shared -fPIC $(CFLAGS) $^ $(MODULES)
- cp $@ ../run/plug/business/test_http/
+#test_http.so:test_http.o
+# $(CC) -o $@ -shared -fPIC $(CFLAGS) $^ $(MODULES)
+# cp $@ ../run/plug/business/test_http/
test_sapp_so:test_sapp_so.c
$(CC) -o $@ -fPIC $(CFLAGS) $^ $(INCS) -L/opt/MESA/lib -lMESA_IP_PLUG -lpcap -lmarsio
-test_ct_plug.so:test_ct_plug.c
- $(CC) -o $@ -shared -fPIC $(CFLAGS) $(INCS) $^ $(MODULES)
- cp $@ ../run/plug/business/test_ct_plug/
+#test_ct_plug.so:test_ct_plug.c
+# $(CC) -o $@ -shared -fPIC $(CFLAGS) $(INCS) $^ $(MODULES)
+# cp $@ ../run/plug/business/test_ct_plug/
.c.o:
$(CC) -c -o $@ $(CFLAGS) -I. $(INCS) $<
diff --git a/test_so/sysinfo.log b/test_so/sysinfo.log
deleted file mode 100644
index cf9aaa4..0000000
--- a/test_so/sysinfo.log
+++ /dev/null
@@ -1,46 +0,0 @@
-
-*********************** sysinfo exactly *************************
-RCV-PKT total_pkt total_len pps Bps
-Ethernet 0 0 0 0
-IPv4 644 54180 9 702
-IPv6 0 0 0 0
-TCP 139 3952 0 0
-UDP 505 34568 9 522
-Unknown 0 0 0 0
-
-***************************************************************
-SND-PKT total_pkt total_len pps Bps
-TCP_RST 0 0 0 0
-TCP_S/A 0 0 0 0
-UDP 0 0 0 0
-
-TUNNEL total_pkt total_len
-6over4 0 0
-teredo 0 0
-
-------------------------------- TCP statistics detail -----------------------------
- |-----------Current---------| |------Realtime-----| |--------From-of-startup---------|
-tid link-syn link-data link-nouse link-new/s link-del/s stream-num reset-num hash-list-max
- 0 0 0 2 0 0 2 0 0
-
--------------------------- UDP statistics detail ------------------------
- |-----------Current---------| |------Realtime-----| |--From-of-startup--|
-tid link-one link-two link-more link-new/s link-del/s stream-num reset-num
- 0 5 2 19 1 0 26 0
-*****************************************************************
-
-################# sysinfo humanly --- is same as above! #########
-RCV-PKT total_pkt total_len pps bps
-Ethernet 0 0 0 0
-IPv4 644 52.91K 9 5.48K
-IPv6 0 0 0 0
-TCP 139 3.86K 0 0
-UDP 505 33.76K 9 4.08K
-Unknown 0 0 0 0
-#################################################################
-SND-PKT total_pkt total_len pps bps
-TCP_RST 0 0 0 0
-TCP_S/A 0 0 0 0
-UDP 0 0 0 0
-#################################################################
-