summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlijia <[email protected]>2021-08-03 15:58:14 +0800
committerlijia <[email protected]>2021-08-03 15:58:14 +0800
commitb72afadb9f8a4dabb6c4fe7a7273d575196e9be1 (patch)
tree1ace93997663087fc42f8a1971788272b3a55832
parentce0dfaf375577b1e5204efe78d4c684aa064e6e2 (diff)
TSG-7243, 实时输出保活状态到prometheus.
-rw-r--r--include/private/sendpacket.h11
-rw-r--r--src/entry/sapp_global_val.c222
-rw-r--r--src/inner_plug/CMakeLists.txt2
-rw-r--r--src/inner_plug/g_device_plug.cpp (renamed from src/inner_plug/g_device_plug.c)720
-rw-r--r--src/packet_io/packet_io_hook.c28
5 files changed, 507 insertions, 476 deletions
diff --git a/include/private/sendpacket.h b/include/private/sendpacket.h
index 93faba1..3688488 100644
--- a/include/private/sendpacket.h
+++ b/include/private/sendpacket.h
@@ -467,6 +467,9 @@ int sendpacket_do_checksum(unsigned char *buf, int protocol, int len);
int sendpacket_init_packet(int p_size, unsigned char **buf);
int sendpacket_tool_init(void);
extern int sendpacket_write_new( sendpacketTool *pTool,int sendlen, char dir);
+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);
+
#ifdef __cplusplus
}
#endif
@@ -491,17 +494,19 @@ int sendpacket_build_ip(u_int16_t len, u_char tos, u_int16_t id, u_int16_t frag,
int payload_s, char *buf);
int sendpacket_build_ipv4(u_int16_t len, u_int8_t tos, u_int16_t id, u_int16_t frag,
u_int8_t ttl, u_int8_t prot, u_int32_t src, u_int32_t dst,
- const char *payload, int payload_s, char *buf);
+ const char *payload, int payload_s, unsigned char *buf);
+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);
int sendpacket_build_tcp(u_int16_t sp, u_int16_t dp, u_int32_t seq, u_int32_t ack, u_int8_t control,
u_int16_t win, u_int16_t urg, const char *payload, int payload_s,
char *buf);
-int sendpacket_build_udp_dual_stack(u_int16_t sp, u_int16_t dp, const char *payload, int payload_s,int,char *buf);
+int sendpacket_build_udp_dual_stack(u_int16_t sp, u_int16_t dp, const char *payload, int payload_s,int,unsigned char *buf);
int sendpacket_build_ethernet(u_char *dst, u_char *src, u_short type,
const u_char *payload, int payload_s, u_char *buf);
int sendpacket_build_arp(u_short hrd, u_short pro, u_char hln, u_char pln, u_short op,
u_char *sha, u_char *spa, u_char *tha, u_char *tpa,
const u_char *payload, int payload_s, u_char *buf);
-int sendpacket_do_checksum(char *buf, int protocol, int len);
+int sendpacket_do_checksum(unsigned char *buf, int protocol, int len);
int sendpacket_init_packet(int p_size, char **buf);
#ifdef __cplusplus
}
diff --git a/src/entry/sapp_global_val.c b/src/entry/sapp_global_val.c
deleted file mode 100644
index 717bb6d..0000000
--- a/src/entry/sapp_global_val.c
+++ /dev/null
@@ -1,222 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "sapp_api.h"
-#include "sapp_private_api.h"
-
-sapp_global_t *sapp_global_val;
-
-struct sapp_global_single_t sapp_global_single;
-struct sapp_global_mthread_t sapp_global_mthread[MAX_THREAD_NUM];
-
-//extern int g_packet_io_thread_num;
-extern int tcpstate_num[MAX_TCP_STATE];
-extern int udpstate_num[MAX_UDP_STATE];
-
-/* ����ʱ��ʹ��ȫ�ֱ���, �Ժ�̬��ȡ�����ļ�,
- overlay�㶨��, ����vxlan�Ļ�����, overlay�����IJ�, eth[0], ipv4[1], udp[2], vxlan[3], ��Щ�㲻��ԭʼ������, ��Ϊ�˱��ڷ�����������IJ�, ���ܵ��ò��,
- ��ʵ�ʻ�ע������ʱҲҪЯ��,
-
- TODO, ��vxlan���������
- ��gdev_keepaliveģ���Ƶ�sapp�ڲ�, ����Ϊ���.so����, ʹ��sapp.toml���ؿ��ƶ����ǿ�plug conflist����.
-
- TODO: �ƶ���ȫ�ֱ���sapp_global_val��.
-*/
-int g_overlay_layer_set[__ADDR_TYPE_MAX][SAPP_SUPPORT_LAYER_NUM_MAX];
-
-/*
- ע����޼��㶨��, ������ʱ�����˲�,
- mirrorģʽ��, ������ע��㲻һ��ʱ, ��rst��Ҫ����vlan, mpls, gtp�Ȳ�,
- ��Ϊ����overlay, overlay��ʽ�϶���Ԥ�ȹ涨�õ�, ����ʵ������һ����Ԥ��ָ��ij��Э�����IJ�,
- ����֧��ģ������, ��*��ʾ, ��vlan[*], gtp[*]��, ��ʾ����ʱ�����˲�϶�����, ��������һ��,
- �����ip-in-ip, ip-gre-ip, 4over6, 6over4��������, ���������ipֱ��ע���ڲ�ip����Ԫ��, �Ƿdz�Σ�յ�,
- ��Ϊ������д��ip[*], Ҳ����д��ip[1], ip[2]����, ��Ѳ��������Ĵ�ip/tcp������,
-
- �������ó�һ����ַ������, ����ͬʱ����ָ���������в�, ������.
-*/
-
-/*
- ����ʱ����ͬʱ����һ��������prune��������, ˳���Ǵ�internal��external,
- ����֧��N����������, mirrorģʽ��, ��ײ��ethernetд��д������,
-
- ����������Ŀgtpԭʼ������Ϊ: ethernet/ipv4/udp/gtp/ipv4/tcp/http, ����gtp������: "gtp[3],udp[2],ip[1]",
-
- ����ijGRE����ԭʼ������Ϊ: ethernet/ipv4/gre/ipv4/udp/dns, �������������������: "gre[2],ip[1]",
- TODO: �ƶ���ȫ�ֱ���sapp_global_val��.
-*/
-
-embed_layer_t g_prune_inject_layer_set[SAPP_PRUNE_LAYER_NUM_MAX];
-
-
-/*
- ������Щ���ǷǶԳƴ��ڲ�, ��C2S��S2C�����п���û����һ��,���´�����compare_addrʱ���಻�Գ�, ��Ҫ����һ���ղ�, ��ע���ʱ����ע��, ��Ҫ����.
- TODO: �ƶ���ȫ�ֱ���sapp_global_val��.
-*/
-asymmetric_presence_layer_t g_asymmetric_presence_layer_set[__ADDR_TYPE_MAX];
-
-
-/*
- ��g_asymmetric_presence_layer_set���岻ͬ, ������Щ���Dz���һ����˫���ַ��һ�µIJ�,
- ��C2S��S2C����IJ�����Ȼ��һ����,��˫��ĵ�ַ��һ��, ��������gtp, gre, mpls��, ethernet, vlanҲ�п���.
- �������ע�����ݰ�, ������˫����,
- ��Ҫ���¶Բ���Ϣ, ע���ʱ����ע��.
- ����ǵ�����, �ҿ�����������, ����ע�����ʧ�ܵ�!!
- TODO: �ƶ���ȫ�ֱ���sapp_global_val��.
-*/
-embed_layer_t g_asymmetric_addr_layer_set;
-
-
-/*
- ����ָ����ЩЭ�����Ϊ��ַ����, ����Ψһȷ��һ����, ���粻ͬ�����ڶ�ʹ��˽�е�ַʱ, ���п��ܳ�ͻ��, Ӧ�ðѵײ�vlan,mpls�Ȳ�Ҳ��Ϊ��ַ�Ƚϲ���,
- TODO: �ƶ���ȫ�ֱ���sapp_global_val��.
-*/
-embed_layer_t g_stream_compare_layer_set;
-
-
-extern char *MESA_MD5_sum_str(unsigned char *raw_data, unsigned int raw_data_len, char result[33]);
-
-static off_t _check_hdr_get_file_length(const char *file_name)
-{
- struct stat file_stat;
-
- if(stat(file_name, &file_stat) == 0)
- {
- return file_stat.st_size;
- }
- return 0;
-}
-
-static void sapp_include_header_check_file(const char *file_name, const char *std_md5_sum_str)
-{
- char file_md5_sum_str[33];
- FILE *fp;
- char *tmp_file_buf;
- off_t file_len;
-
- fp = fopen(file_name, "r");
- if(NULL == fp){
- return;
- }
-
- file_len = _check_hdr_get_file_length(file_name);
- tmp_file_buf = (char *)malloc(file_len);
-
- fread(tmp_file_buf, file_len, 1, fp);
-
- MESA_MD5_sum_str((unsigned char *)tmp_file_buf, file_len, file_md5_sum_str);
-
- if(memcmp(file_md5_sum_str, std_md5_sum_str, 32) != 0){
- printf("\033[33m[Warning]stream_inc header file %s is disaccord with current sapp!\033[0m\n", file_name);
- usleep(200 * 1000);
- }
-
- fclose(fp);
- free(tmp_file_buf);
-
- return;
-}
-
-/* ��⵱ǰ���л����µ�.h����뻷���Ƿ�һ�� */
-void sapp_include_header_check(void)
-{
- const char *hdr_dir;
- char tmp_file_path[1024];
-
- hdr_dir = "/opt/MESA/include/MESA/stream_inc";
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_base.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_BASE_MD5_CHECK);
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_control.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_CONTROL_MD5_CHECK);
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_entry.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_ENTRY_MD5_CHECK);
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_inject.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_INJECT_MD5_CHECK);
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_project.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_PROJECT_MD5_CHECK);
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_proxy.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_PROXY_MD5_CHECK);
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_rawpkt.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_RAWPKT_MD5_CHECK);
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_tunnel.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_TUNNEL_MD5_CHECK);
-
- hdr_dir = "/usr/include/MESA/stream_inc";
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_base.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_BASE_MD5_CHECK);
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_control.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_CONTROL_MD5_CHECK);
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_entry.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_ENTRY_MD5_CHECK);
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_inject.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_INJECT_MD5_CHECK);
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_project.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_PROJECT_MD5_CHECK);
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_proxy.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_PROXY_MD5_CHECK);
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_rawpkt.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_RAWPKT_MD5_CHECK);
-
- snprintf(tmp_file_path, 1024, "%s/%s", hdr_dir, "stream_tunnel.h");
- sapp_include_header_check_file(tmp_file_path, STREAM_TUNNEL_MD5_CHECK);
-}
-
-static inline int mem_alignment_pad(int size)
-{
- return 64 - (size % 64);
-}
-
-void sapp_global_val_sanity_check(void)
-{
- /* ���߳�ȫ�ֱ���size������64�ֽ�������, ������cache�����ͻ, ����Ӱ������ */
- if((sizeof(struct sapp_global_mthread_t) % 64) != 0){
- printf("\033[1;31;40msizeof(struct sapp_global_mthread_t)=%u, is not multiple of 64B!\033[0m\n", sizeof(struct sapp_global_mthread_t));
- printf("\033[1;31;40mYou must add %d bytes padding to sapp_global_mthread_t!\033[0m\n", mem_alignment_pad(sizeof(struct sapp_global_mthread_t)));
- abort();
- }
-
- if((sizeof(sapp_gval_mthread_t) % 64) != 0){
- printf("\033[1;31;40msizeof(sapp_gval_mthread_t)=%u, is not multiple of 64B!\033[0m\n", sizeof(sapp_gval_mthread_t));
- printf("\033[1;31;40mYou must add %d bytes padding to sapp_gval_mthread_t!\033[0m\n", mem_alignment_pad(sizeof(sapp_gval_mthread_t)));
- abort();
- }
-
- if((sizeof(sapp_gval_individual_volatile_t) % 64) != 0){
- printf("\033[1;31;40msizeof(sapp_gval_individual_volatile_t)=%u, is not multiple of 64B!\033[0m\n", sizeof(sapp_gval_individual_volatile_t));
- printf("\033[1;31;40mYou must add %d bytes padding to sapp_gval_individual_volatile_t!\033[0m\n", mem_alignment_pad(sizeof(sapp_gval_individual_volatile_t)));
- abort();
- }
-
- if((sizeof(layer_args_t) % 64) != 0){
- printf("\033[1;31;40msizeof(struct layer_args_t)=%u, is not multiple of 64B!\033[0m\n", sizeof(layer_args_t));
- abort();
- }
-
- sapp_include_header_check();
- if(INDEPENDENT_SEND_QUEUE_MAX_NUM > MAX_THREAD_NUM){
- printf("\033[1;31;40m INDEPENDENT_SEND_QUEUE_MAX_NUM(%d) > MAX_THREAD_NUM(%d)!\033[0m\n", INDEPENDENT_SEND_QUEUE_MAX_NUM, MAX_THREAD_NUM);
- abort();
- }
-
-}
-
-
-#ifdef __cplusplus
-}
-#endif
-
diff --git a/src/inner_plug/CMakeLists.txt b/src/inner_plug/CMakeLists.txt
index da2b978..702b4ae 100644
--- a/src/inner_plug/CMakeLists.txt
+++ b/src/inner_plug/CMakeLists.txt
@@ -24,7 +24,7 @@ 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(inner_plug STATIC g_device_plug.c)
+add_library(inner_plug STATIC g_device_plug.cpp)
if(ENABLE_STATIC_LINK)
add_library(sapp_assistant STATIC sapp_assistant.cpp)
diff --git a/src/inner_plug/g_device_plug.c b/src/inner_plug/g_device_plug.cpp
index 047d304..54b4384 100644
--- a/src/inner_plug/g_device_plug.c
+++ b/src/inner_plug/g_device_plug.cpp
@@ -1,6 +1,4 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
+
/*
��WY��Ŀ��������, �Ƿ���GDEV�����Ǹ��ݲ��������״̬��̬����, �������ٹ̶�һֱ����,
@@ -18,6 +16,8 @@ extern "C" {
#include "sapp_api.h"
#include "sapp_private_api.h"
+#include "field_stat2.h"
+
#if IOMODE_MARSIO
static struct mr_instance * gdev_plug_extern_marsio4_instance; /* dlopen dynamic link 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);
@@ -30,7 +30,10 @@ extern void (*ptr_marsio_buff_free)(struct mr_instance * instance, marsio_buff_t
__attribute__((__used__)) const char *g_device_plug_git_ver = GIT_VERSION;
#endif
-#define MAX_GDEV_STAT_LOG_NUM (64)
+#define MAX_SUPPORT_GDEV_NUM (16) /* ÿ���߳������֧��inline device������, ���ݷ������Ժ��߳����IJ�ͬ, ��Сֵ��MAX_SUPPORT_GDEV_NUM, ���ֵ��MAX_SUPPORT_GDEV_NUM * sapp_thread_count */
+#define MAX_VXLAN_SERVICE_NUM (256) /* Ŀǰ���֧��255�ֲ�ͬҵ��, �����±������255 */
+
+#define MAX_NO_PKT_TIMEOUT (120) /* ������ô��ʱ��һֱû�����, �Ѵ��豸�޳� */
static void *gdev_kp_log_handle;
enum prog_work_mode_t{
@@ -38,25 +41,63 @@ enum prog_work_mode_t{
PROG_MODE_SLAVE = 2,
};
+
+enum gdev_keepalive_fs2_column_t{
+ FS2_COLUMN_REQUEST_NUM = 0,
+ FS2_COLUMN_REPLY_NUM,
+ __FS2_COLUMN_MAX,
+};
+
+static int gdev_keepalive_fs2_column_id_array[__FS2_COLUMN_MAX];
+
+/*
+ ÿ���߳�, ÿ��Inline-DEV-IP, ÿ��ҵ��ֱ�ͳ��.
+*/
+
typedef struct {
- int active_flag; /* ��IP���� */
- int gdev_keepalive_type;
- int gdev_keepalive_service_num; /* BFD��ȡ */
+ int gdev_keepalive_type; /* for example: GDEV_KEEPALIVE_TYPE_BFD */
+ //int gdev_keepalive_service_num;
+ unsigned int keepalive_request_num; /* ��ǰҵ�񱣻����������, ÿ��һ��ʱ������ */
+ unsigned int keepalive_reply_num; /* ��ǰҵ�񱣻�Ӧ�������, ����service��ͬ, ����ijЩҵ����ⲻ�ظ�Ӧ��, ����request����һ������reply */
+ int field_stat_line_id; /* fs2 �������id */
+ time_t last_time; /* ��ǰҵ�����һ���յ��������ʱ�� */
+}gdev_keepalive_status_per_service_t;
+
+
+typedef struct{
+ int inuse_flag; /* ��λ�ñ�ռ�� */
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;
+ unsigned int keepalive_request_num; /* ��ǰ�豸�������������, ÿ��һ��ʱ������ */
+ unsigned int keepalive_reply_num; /* ��ǰ�豸����Ӧ�������, ����service��ͬ, ����ijЩҵ����ⲻ�ظ�Ӧ��, ����request����һ������reply */
+ int fs2_line_id;
+ time_t last_time; /* ��ǰ�豸���һ���յ��������ʱ�� */
+ gdev_keepalive_status_per_service_t service_array[MAX_VXLAN_SERVICE_NUM]; /* ��BFDЭ���������service, ICMPĬ�϶���0��ҵ�� */
+}gdev_keepalive_status_per_dev_t;
-static gdev_keepalive_status_t GDEV_KEEPALIVE_STAT[MAX_THREAD_NUM][MAX_GDEV_STAT_LOG_NUM];
+
+struct _gdev_keepalive_status_per_thread{
+ gdev_keepalive_status_per_dev_t gdev_array[MAX_SUPPORT_GDEV_NUM];
+}__attribute__ ((aligned (64)));
+
+typedef struct _gdev_keepalive_status_per_thread gdev_keepalive_status_per_thread_t;
+
+
+/*
+ ˵��: gdev�ı���״̬����һ����������, ��Ϊ���Ȳ�֪������,
+
+ ��Ϊʲô����hash? ����? ��̬����?
+
+ ����ģʽ�Ƕ���߳�д, һ���̶߳�ȡ���������, ����Ƕ�̬�����ݽṹ, �ⲻ��Ҫ����,
+ ʹ���������ȷ��������ڴ�, ����־λinuse_flag��ʾ�Ƿ���ʹ��, ��֤��д����ͻ.
+*/
+static gdev_keepalive_status_per_thread_t GDEV_KEEPALIVE_STAT[MAX_THREAD_NUM];
+
+static void *gdev_keepalive_fs2_handle;
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��ҵ����Ƿ񱣻� */
-static int GDEV_KEEPALIVE_LOG_SWITCH = 1;
+static struct gdev_keepalive_service_ctrl g_dev_keepalive_service_ctrl_array[MAX_VXLAN_SERVICE_NUM];/* ����ij��ҵ����Ƿ񱣻� */
//extern int g_packet_io_thread_num;
//extern time_t g_CurrentTime;
@@ -80,39 +121,88 @@ static int gdev_kp_action_judge(int service_id)
}
+/*
+ prometheus fs2 line���Ʋ��ܰ�����Щ�ַ�:
+ const char* reserverd="|:\n\r. \t<>[]#!@";
+
+ ����ip��ַ�ķָ�����Ҫ�ij�'_'
+*/
+static const char *fs2_inet_ntop(unsigned int gip_net, char *buf, int buf_len)
+{
+ const unsigned char *ip_char_array = (unsigned char *)&gip_net;
+
+ snprintf(buf, buf_len, "%u_%u_%u_%u", ip_char_array[0], ip_char_array[1],ip_char_array[2], ip_char_array[3]);
+
+ return buf;
+}
+
+
+static int gdev_keepalive_dynamic_register_fs2_line(gdev_keepalive_status_per_dev_t *cur_dev_stat, unsigned int gip_net)
+{
+ char ip_fs2_string[INET6_ADDRSTRLEN];
+
+ fs2_inet_ntop(gip_net, ip_fs2_string, sizeof(ip_fs2_string));
+
+ cur_dev_stat->fs2_line_id = FS_register(gdev_keepalive_fs2_handle, FS_STYLE_LINE, FS_CALC_SPEED, ip_fs2_string);
+
+ return 0;
+}
+
+
static void gdev_keepalive_stat_update(int tid, unsigned int gip_net, int type, int service_id, int action)
{
- int index;
+ gdev_keepalive_status_per_thread_t *cur_thread_stat = &GDEV_KEEPALIVE_STAT[tid];
+ int bingo = 0, index;
- for(index = 0; index < MAX_GDEV_STAT_LOG_NUM; index++){
- if(0 == GDEV_KEEPALIVE_STAT[tid][index].active_flag){
+ for(index = 0; index < MAX_SUPPORT_GDEV_NUM; index++){
+ if((1 == cur_thread_stat->gdev_array[index].inuse_flag)
+ && (gip_net == cur_thread_stat->gdev_array[index].gdev_ip_network_order)){
+ bingo = 1;
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 this inline device */
+ if(0 == bingo){
+ /* search a empty place */
+ for(index = 0; index < MAX_SUPPORT_GDEV_NUM; index++){
+ if(0 == cur_thread_stat->gdev_array[index].inuse_flag){
+ cur_thread_stat->gdev_array[index].inuse_flag = 1;
+ break;
+ }
}
+
+ if(index >= MAX_SUPPORT_GDEV_NUM){
+ MESA_handle_runtime_log(gdev_kp_log_handle, RLOG_LV_FATAL, "[gdev_keepalive]",
+ "Too many inline devices, max support: %d!\n", MAX_SUPPORT_GDEV_NUM);
+ return;
+ }
+
+ /* ��ǰ�豸ip�״η���, ��̬ע�ᵽfs2 */
+ gdev_keepalive_dynamic_register_fs2_line(&cur_thread_stat->gdev_array[index], gip_net);
}
- /* 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);
+ if(service_id < 0 || service_id >= MAX_VXLAN_SERVICE_NUM){
+ MESA_handle_runtime_log(gdev_kp_log_handle, RLOG_LV_INFO, "[gdev_keepalive]",
+ "invalid service num: %d!\n", service_id);
return;
}
+
+ /* update this device */
+ cur_thread_stat->gdev_array[index].inuse_flag = 1;
+ cur_thread_stat->gdev_array[index].gdev_ip_network_order = gip_net;
+ cur_thread_stat->gdev_array[index].last_time = g_CurrentTime;
+ cur_thread_stat->gdev_array[index].keepalive_request_num++;
+ cur_thread_stat->gdev_array[index].keepalive_reply_num++;
+
+ /* update by service */
+ cur_thread_stat->gdev_array[index].service_array[service_id].gdev_keepalive_type = type;
+ cur_thread_stat->gdev_array[index].service_array[service_id].keepalive_request_num++;
+ if(action){
+ cur_thread_stat->gdev_array[index].service_array[service_id].keepalive_reply_num++;
+ }
+ cur_thread_stat->gdev_array[index].service_array[service_id].last_time = g_CurrentTime;
- 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;
}
@@ -155,11 +245,12 @@ static int gdev_keepalive_bfd_plug(const raw_pkt_t *raw_pkt, int thread_id, unsi
service_id = vxlan_sport_map_to_service_id(ntohs(udp_hdr->uh_sport));
action = gdev_kp_action_judge(service_id);
+ /* ��ʹaction=0, stat_updateҲҪ����, ��Ҫͳ�Ʋ��ظ������ҵ����Ϣ */
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);
@@ -363,64 +454,6 @@ static inline int gdev_bfd_pkt_identify(const struct streaminfo *a_udp)
}
-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;
@@ -429,12 +462,14 @@ 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;
+ int tid, dev_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;
+ for(dev_num = 0; dev_num < MAX_SUPPORT_GDEV_NUM; dev_num++){
+ if(GDEV_KEEPALIVE_STAT[tid].gdev_array[dev_num].inuse_flag != 0){
+ rcv_sum += GDEV_KEEPALIVE_STAT[tid].gdev_array[dev_num].keepalive_request_num;
+ snd_sum += GDEV_KEEPALIVE_STAT[tid].gdev_array[dev_num].keepalive_reply_num;
+ }
}
}
@@ -447,172 +482,176 @@ static void __gdev_keepalive_pkt_calc_pps(void)
return;
}
-static void *gdev_keepalive_log_thread(void *arg)
+
+static void gdev_keepalive_update_local_log(void)
{
FILE *gdev_status_fp;
- int index, thread_seq;
+ int dev_index, thread_seq, service_index;
int platform_thread_num;
char cur_time_str[64];
- char tmp_ip_str[32];
+ char tmp_ip_str[INET6_ADDRSTRLEN];
const char *tmp_keealive_type;
time_t last_op_time;
-
- last_op_time = time(NULL);
-
- MESA_mkdir_p(sapp_global_val->config.data_file_path.data_files_root_dir, 0755);
+ const gdev_keepalive_status_per_thread_t *this_thread_stat;
+ const gdev_keepalive_status_per_dev_t *this_dev_stat;
- while(1){
- gdev_status_fp = fopen(ABBR_INLINE_KEEPALIVE_LOG_DATA_FILE, "w+");
- if(NULL == gdev_status_fp){
- sleep(1);
- continue;
- }
- platform_thread_num = get_thread_count();
- timet_to_str(time(NULL), 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");
+ gdev_status_fp = fopen(ABBR_INLINE_KEEPALIVE_LOG_DATA_FILE, "w+");
+ if(NULL == gdev_status_fp){
+ return;
+ }
+
+ platform_thread_num = get_thread_count();
+ timet_to_str(time(NULL), 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++)
+ {
+ this_thread_stat = &GDEV_KEEPALIVE_STAT[thread_seq];
- 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);
+ for(dev_index = 0; dev_index < MAX_SUPPORT_GDEV_NUM; dev_index++){
+ if(0 == this_thread_stat->gdev_array[dev_index].inuse_flag){
+ continue;
}
- }
- __gdev_keepalive_pkt_calc_pps();
-
- fclose(gdev_status_fp);
+ this_dev_stat = &this_thread_stat->gdev_array[dev_index];
+ inet_ntop(AF_INET, &this_dev_stat->gdev_ip_network_order, tmp_ip_str, sizeof(tmp_ip_str));
- while(last_op_time == time(NULL)){
- usleep(100);
+ for(service_index = 0; service_index < MAX_VXLAN_SERVICE_NUM; service_index++){
+ if(this_dev_stat->service_array[service_index].keepalive_request_num > 0){
+ if(GDEV_KEEPALIVE_TYPE_ICMP == this_dev_stat->service_array[service_index].gdev_keepalive_type){
+ tmp_keealive_type = "ICMP";
+ }else if(GDEV_KEEPALIVE_TYPE_BFD == this_dev_stat->service_array[service_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,
+ service_index,
+ gdev_kp_action_judge(service_index),
+ tmp_keealive_type,
+ this_dev_stat->service_array[service_index].keepalive_request_num,
+ this_dev_stat->service_array[service_index].keepalive_reply_num);
+ }
+ }
+
}
- last_op_time = time(NULL);
}
+
+ fclose(gdev_status_fp);
- return NULL;
}
-static int gdev_kp_update_service_ctrl(const struct gdev_keepalive_service_ctrl *service_ctrl)
+
+
+
+static void gdev_keepalive_update_fs2(void)
{
- if((service_ctrl->service_num < 0) || (service_ctrl->service_num >= MAX_VXLAN_SERVICE_NUM)){
- return -1;
- }
+ const gdev_keepalive_status_per_thread_t *this_thread_stat;
+ const gdev_keepalive_status_per_dev_t *this_dev_stat;
+ int dev_index, thread_seq, service_index;
+ int platform_thread_num;
- g_dev_keepalive_service_ctrl_array[service_ctrl->service_num].keepalive_switch = service_ctrl->keepalive_switch;
+ platform_thread_num = get_thread_count();
- return 0;
+ for(thread_seq = 0; thread_seq < platform_thread_num; thread_seq++)
+ {
+ this_thread_stat = &GDEV_KEEPALIVE_STAT[thread_seq];
+
+ for(dev_index = 0; dev_index < MAX_SUPPORT_GDEV_NUM; dev_index++){
+ if(0 == this_thread_stat->gdev_array[dev_index].inuse_flag){
+ continue;
+ }
+ this_dev_stat = &this_thread_stat->gdev_array[dev_index];
+
+ FS_operate(gdev_keepalive_fs2_handle, this_dev_stat->fs2_line_id, gdev_keepalive_fs2_column_id_array[FS2_COLUMN_REQUEST_NUM], FS_OP_SET, this_dev_stat->keepalive_request_num);
+ FS_operate(gdev_keepalive_fs2_handle, this_dev_stat->fs2_line_id, gdev_keepalive_fs2_column_id_array[FS2_COLUMN_REPLY_NUM], FS_OP_SET, this_dev_stat->keepalive_reply_num);
+ }
+ }
+
}
-int gdev_keepalive_set_opt(const SAPP_TLV_T *tlv_value)
+
+static void gdev_keepalive_clear_stat(void)
{
- int ret = 0;
- static time_t last_log_time = 0;
+ int platform_thread_num, dev_index, thread_seq, service_index;
+ gdev_keepalive_status_per_thread_t *this_thread_stat;
+ gdev_keepalive_status_per_dev_t *this_dev_stat;
- 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;
+ platform_thread_num = get_thread_count();
+ for(thread_seq = 0; thread_seq < platform_thread_num; thread_seq++){
+ this_thread_stat = &GDEV_KEEPALIVE_STAT[thread_seq];
- 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);
- }
+ for(dev_index = 0; dev_index < MAX_SUPPORT_GDEV_NUM; dev_index++){
+ if(0 == this_thread_stat->gdev_array[dev_index].inuse_flag){
+ continue;
}
- }
- 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;
+ this_dev_stat = &this_thread_stat->gdev_array[dev_index];
+
+ this_dev_stat->keepalive_request_num = 0;
+ this_dev_stat->keepalive_reply_num = 0;
+
+#if 0 /* �Ȳ�֧����̭, ��Ϊ��ǰ�豸��line_id�Ѿ�ע�ᵽfs2, ����ʹ�õĻ�, name�޷����� */
+ if(this_dev_stat->last_time + MAX_NO_PKT_TIMEOUT < g_CurrentTime){
+ char dev_ip_str[INET6_ADDRSTRLEN];
+ this_dev_stat->inuse_flag = 0;
+ inet_ntop(AF_INET, &this_dev_stat->gdev_ip_network_order, dev_ip_str, sizeof(dev_ip_str));
+ MESA_handle_runtime_log(gdev_kp_log_handle, RLOG_LV_INFO, "[gdev_keepalive]", " %s timeout, delete it.\n", dev_ip_str);
+ }
+#endif
+ for(service_index = 0; service_index < MAX_VXLAN_SERVICE_NUM; service_index++){
+ if(this_dev_stat->service_array[service_index].keepalive_request_num > 0){
+ this_dev_stat->service_array[service_index].keepalive_request_num = 0;
+ this_dev_stat->service_array[service_index].keepalive_reply_num = 0;
+ }
}
}
- break;
-
- default:
- ret = -2;
- break;
}
-
- return ret;
}
-int gdev_keepalive_get_opt(SAPP_TLV_T *tlv_value)
+
+static void *gdev_keepalive_log_thread(void *arg)
{
- int ret = 0;
+ time_t last_op_time = time(NULL);
- if((NULL == tlv_value) || (tlv_value->length <= 0)){
- return -1;
+ MESA_mkdir_p(sapp_global_val->config.data_file_path.data_files_root_dir, 0755);
+
+ while(SAPP_STATE_PROCESSING != sapp_get_current_state()){
+ sapp_usleep(100);
}
- switch(tlv_value->type){
-
- case GDEV_KEEPALIVE_OPT_GLOBAL_SWITCH:
- {
- tlv_value->int_value = g_dev_keepalive_flag;
+ while(1){
+ while(last_op_time == time(NULL)){
+ sapp_usleep(100);
}
- break;
+ last_op_time = time(NULL);
+ __gdev_keepalive_pkt_calc_pps();
+ gdev_keepalive_update_local_log();
+ gdev_keepalive_update_fs2();
+ gdev_keepalive_clear_stat(); /* ÿ����ռ���, ֻ����һ��ʱ������� */
+ }
- case GDEV_KEEPALIVE_OPT_RCV_PKT_PPS:
- {
- tlv_value->long_value = _gdev_keepalive_rcv_pps;
- }
- break;
+ return NULL;
+}
- case GDEV_KEEPALIVE_OPT_SND_PKT_PPS:
- {
- tlv_value->long_value = _gdev_keepalive_snd_pps;
- }
- break;
-
- default:
- ret = -1;
- break;
+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;
}
-
- return ret;
+
+ g_dev_keepalive_service_ctrl_array[service_ctrl->service_num].keepalive_switch = service_ctrl->keepalive_switch;
+
+ return 0;
}
+
+
/* vxlan���⻷����, vpn-id, Դ�˿ں�ҵ��ID֮��Ĺ�ϵ, �����ļ���ʽ:
service-id VPN-id Sport-range
@@ -715,16 +754,54 @@ done:
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)
+static int gdev_keepalive_fs2_init(void)
{
- return (unsigned char)(vxlan_id - 100);
+ int fs2_opt;
+ unsigned short fs_server_port;
+
+ gdev_keepalive_fs2_handle = FS_create_handle();
+
+ /*
+ prometheus��ص�����, �� sapp_fs2_init() ��ʼ��.
+ */
+
+ fs2_opt = 5;
+ FS_set_para(gdev_keepalive_fs2_handle, STAT_CYCLE, &fs2_opt, sizeof(int));
+
+ fs2_opt = 1; /* 1:Rewrite ,2: Append. */
+ FS_set_para(gdev_keepalive_fs2_handle, PRINT_MODE, &fs2_opt, sizeof(int));
+
+ fs2_opt = 0;
+ FS_set_para(gdev_keepalive_fs2_handle, PRINT_TRIGGER, &fs2_opt, sizeof(int));
+ //FS_set_para(gdev_keepalive_fs2_handle, OUTPUT_DEVICE, "./inline_keepalive.log", strlen("./inline_keepalive.log") + 1);
+
+ fs2_opt = 1;
+ FS_set_para(gdev_keepalive_fs2_handle, NOT_SEND_METRIC_TO_SERVER, &fs2_opt, sizeof(int));
+
+ FS_set_para(gdev_keepalive_fs2_handle, APP_NAME, "keepalive", strlen("keepalive")+1);
+
+ FS_set_para(gdev_keepalive_fs2_handle, STATS_SERVER_IP, (void *)sapp_global_val->config.profiling.log.remote.server_ip, strlen(sapp_global_val->config.profiling.log.remote.server_ip)+1);
+ fs_server_port = (unsigned short)sapp_global_val->config.profiling.log.remote.server_port;
+ FS_set_para(gdev_keepalive_fs2_handle, STATS_SERVER_PORT, &fs_server_port, sizeof(short));
+
+ fs2_opt = 1;
+ FS_set_para(gdev_keepalive_fs2_handle, OUTPUT_PROMETHEUS, &fs2_opt, sizeof(int));
+
+
+ /* ��ע����, ��ʼ����̶�����, ����ipΪ��λ��̬ע��, gdev_keepalive_dynamic_register_fs2_line() */
+ gdev_keepalive_fs2_column_id_array[FS2_COLUMN_REQUEST_NUM] = FS_register(gdev_keepalive_fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, "req_pkt");
+ gdev_keepalive_fs2_column_id_array[FS2_COLUMN_REPLY_NUM] = FS_register(gdev_keepalive_fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, "rpy_pkt");
+
+ FS_start(gdev_keepalive_fs2_handle);
+
+ return 0;
}
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* �������vxlanģʽ��, ���ݰ��Ƿ�������� */
int vxlan_packet_is_myself(const raw_pkt_t *rawpkt)
{
@@ -737,6 +814,168 @@ int vxlan_packet_is_myself(const raw_pkt_t *rawpkt)
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);
+}
+
+
+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;
+}
+
+
+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;
+}
+
+
int gdev_keepalive_plug_init(void)
{
char tmp_ip_buf[16];
@@ -750,7 +989,8 @@ int gdev_keepalive_plug_init(void)
MESA_handle_runtime_log(gdev_kp_log_handle, 30, "[gdev_keepalive]", "g_device_plug version: %s\n", g_device_plug_git_ver);
#endif
- assert(sizeof(gdev_keepalive_status_t) % 64 == 0);
+ /* ���߳�ģʽ��α��������, 64B������� */
+ assert(sizeof(gdev_keepalive_status_per_thread_t) % 64 == 0);
opt_len = sizeof(deploy_mode_string);
if(sapp_get_platform_opt(SPO_DEPLOYMENT_MODE_STR, (void *)deploy_mode_string, &opt_len) < 0){
@@ -776,7 +1016,7 @@ int gdev_keepalive_plug_init(void)
inet_pton(AF_INET, tmp_ip_buf, &sendto_gdev_card_ip);
MESA_load_profile_int_def((char *)ABBR_INLINE_DEV_CONF_FILE, (char *)"Module", (char *)"default_keepalive_action", &g_dev_keepalive_default_action, 1);
- MESA_load_profile_int_def((char *)ABBR_INLINE_DEV_CONF_FILE, (char *)"Module", (char *)"gdev_status_switch", &GDEV_KEEPALIVE_LOG_SWITCH, 1);
+ ///MESA_load_profile_int_def((char *)ABBR_INLINE_DEV_CONF_FILE, (char *)"Module", (char *)"gdev_status_switch", &GDEV_KEEPALIVE_LOG_SWITCH, 1);
for(i = 0; i < MAX_VXLAN_SERVICE_NUM; i++){
@@ -786,11 +1026,13 @@ int gdev_keepalive_plug_init(void)
vxlan_sport_service_map_init();
- if(GDEV_KEEPALIVE_LOG_SWITCH){
- pthread_t log_pid;
- pthread_create(&log_pid, NULL, gdev_keepalive_log_thread, NULL);
+ if(gdev_keepalive_fs2_init() < 0){
+ return -1;
}
-
+
+ pthread_t log_pid;
+ pthread_create(&log_pid, NULL, gdev_keepalive_log_thread, NULL);
+
return 0;
}
diff --git a/src/packet_io/packet_io_hook.c b/src/packet_io/packet_io_hook.c
index 5485b1b..a89139a 100644
--- a/src/packet_io/packet_io_hook.c
+++ b/src/packet_io/packet_io_hook.c
@@ -175,17 +175,23 @@ static int packet_io_hook_input_vxlan(raw_pkt_t *raw_pkt, unsigned char dir, int
const struct mesa_ip4_hdr *ip4hdr = (struct mesa_ip4_hdr *)((char *)raw_pkt->raw_pkt_data + sizeof(struct mesa_ethernet_hdr));
const struct mesa_udp_hdr *carry_vxlan_udp_hdr;
const inline_vxlan_hdr_t *vxlan_hdr;
-
- if(ip4hdr->ip_p != IPPROTO_UDP){
- sapp_runtime_log(RLOG_LV_INFO, "packet_io_hook_input_vxlan: recv not udp packet, IPPROTO:%d", ip4hdr->ip_p);
- return -1;
- }
-
- carry_vxlan_udp_hdr = (struct mesa_udp_hdr *)((char *)raw_pkt->raw_pkt_data + sizeof(struct mesa_ethernet_hdr) + sizeof(struct mesa_ip4_hdr));
- if(carry_vxlan_udp_hdr->uh_dport != htons(VXLAN_KEEPALIVE_PKT_PORT)
- && carry_vxlan_udp_hdr->uh_dport != htons(VXLAN_OVERLAY_PKT_PORT)){
- sapp_runtime_log(RLOG_LV_INFO, "packet_io_hook_input_vxlan: recv dst udp port:%u, not %u and not %u in vxlan mode\n",
- ntohs(carry_vxlan_udp_hdr->uh_dport), VXLAN_KEEPALIVE_PKT_PORT, VXLAN_OVERLAY_PKT_PORT);
+ const struct mesa_icmp_echo_hdr *icmp_hdr;
+
+ if(IPPROTO_UDP == ip4hdr->ip_p){
+ carry_vxlan_udp_hdr = (struct mesa_udp_hdr *)((char *)raw_pkt->raw_pkt_data + sizeof(struct mesa_ethernet_hdr) + sizeof(struct mesa_ip4_hdr));
+ if(carry_vxlan_udp_hdr->uh_dport != htons(VXLAN_KEEPALIVE_PKT_PORT)
+ && carry_vxlan_udp_hdr->uh_dport != htons(VXLAN_OVERLAY_PKT_PORT)){
+ sapp_runtime_log(RLOG_LV_DEBUG, "packet_io_hook_input_vxlan: recv dst udp port:%u, not %u and not %u in vxlan mode\n",
+ ntohs(carry_vxlan_udp_hdr->uh_dport), VXLAN_KEEPALIVE_PKT_PORT, VXLAN_OVERLAY_PKT_PORT);
+ return -1;
+ }
+ }else if(IPPROTO_ICMP == ip4hdr->ip_p){
+ icmp_hdr = (struct mesa_icmp_echo_hdr *)((char *)ip4hdr + ip4hdr->ip_hl*4);
+ if(icmp_hdr->icmp_type != ICMP_ECHO){
+ return -1;
+ }
+ }else{
+ sapp_runtime_log(RLOG_LV_DEBUG, "packet_io_hook_input_vxlan: recv not udp and icmp packet, IPPROTO:%d", ip4hdr->ip_p);
return -1;
}