diff options
| -rw-r--r-- | .gitlab-ci.yml | 4 | ||||
| -rw-r--r-- | CMakeLists.txt | 6 | ||||
| -rw-r--r-- | include/private/stream_internal.h | 116 | ||||
| -rw-r--r-- | include/public/stream_inc/stream_control.h | 745 | ||||
| -rw-r--r-- | module_test/src/gtest_main.cpp | 19 | ||||
| -rw-r--r-- | module_test/src/gtest_sapp_fun.h | 19 | ||||
| -rw-r--r-- | module_test/src/gtest_sapp_support.cpp | 79 | ||||
| -rw-r--r-- | module_test/src/gtest_sapp_support_plug.cpp | 129 | ||||
| -rw-r--r-- | src/dealpkt/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/dealpkt/plug_support.c | 19 | ||||
| -rw-r--r-- | src/support/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/support/ulid/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/support/ulid/ulid_struct.hh | 708 | ||||
| -rw-r--r-- | src/support/ulid/ulid_wrap.cpp | 21 | ||||
| -rw-r--r-- | src/support/ulid/ulid_wrap.h | 13 | ||||
| -rw-r--r-- | vendor/CMakeLists.txt | 1 |
16 files changed, 1356 insertions, 530 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index af15b13..ef0e96c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,8 @@ variables: BUILD_IMAGE_X86_64_ROCKY8: "git.mesalab.cn:7443/mesa_platform/build-env:rocky8-for-sapp" BUILD_IMAGE_AARCH64_ROCKY9: "git.mesalab.cn:7443/mesa_platform/build-env:rocky9-aarch64" INSTALL_DEPENDENCY_LIBRARY: - framework_env libcjson-devel libbreakpad_mini-devel libuuid-devel + systemd-devel + framework_env libcjson-devel libbreakpad_mini-devel libuuid-devel libuuid libMESA_htable-devel libMESA_prof_load-devel libMESA_handle_logger-devel libMESA_field_stat2-devel libfieldstat3-devel libfieldstat4-devel hasp-tools @@ -48,6 +49,7 @@ stages: --suppress=preprocessorErrorDirective --suppress=syntaxError --suppress=*:${CI_PROJECT_DIR}/src/support/ap_bloom/deps/* + --suppress=*:${CI_PROJECT_DIR}/src/support/ulid/* run_cppcheck_for_x86_64_rocky8: extends: .cppcheck_script diff --git a/CMakeLists.txt b/CMakeLists.txt index 8315a0a..cd316e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,7 +194,7 @@ elseif(MEM_POOL STREQUAL "MIMALLOC") add_definitions(-DUSE_MIMALLOC=1) endif() -# 定义宏 LIBEVENT_ENABLED +# 定义�? LIBEVENT_ENABLED option(LIBEVENT_ENABLED "Enable libevent" OFF) if(LIBEVENT_ENABLED STREQUAL "ON") add_definitions(-DLIBEVENT_ENABLED=1) @@ -209,7 +209,7 @@ endif() add_definitions(${CAPTURE_DEFINITIONS} ${MEM_POOL_DEFINITIONS} -D__FAVOR_BSD=1 -D__USE_BSD=1 -D_GNU_SOURCE=1 -DMESA_SAPP_PLATFORM=1) -set(SAPP_DEPEND_DYN_LIB MESA_handle_logger MESA_prof_load MESA_htable MESA_field_stat2 fieldstat3 fieldstat4 cjson breakpad_mini ${SYSTEMD_LIBRARIES} pthread dl pcap) +set(SAPP_DEPEND_DYN_LIB MESA_handle_logger MESA_prof_load MESA_htable MESA_field_stat2 fieldstat3 fieldstat4 cjson breakpad_mini ${SYSTEMD_LIBRARIES} pthread dl pcap uuid) set(SAPP_DEPEND_DYN_LIB ${SAPP_DEPEND_DYN_LIB} packet_io_pcap) if(CAPTURE_MODE STREQUAL "MARSIO") set(SAPP_DEPEND_DYN_LIB ${SAPP_DEPEND_DYN_LIB} packet_io_marsio) @@ -225,7 +225,7 @@ set(SAPP_MODULES timestamp_record md5 config timer tomlc99_wrap dpdk_ip_hash gdev_assistant inline_keepalive ap_bloom libdabloom sapp_dev sapp_assistant sapp_metrics - platform_support cpu_limit timeout token_bucket) + platform_support cpu_limit timeout token_bucket ulid) if(LIBEVENT_ENABLED STREQUAL "ON") set(SAPP_MODULES ${SAPP_MODULES} libevent-static) diff --git a/include/private/stream_internal.h b/include/private/stream_internal.h index f68b518..044bc32 100644 --- a/include/private/stream_internal.h +++ b/include/private/stream_internal.h @@ -17,8 +17,8 @@ //#define STREAM_TUNNEL_MD5_CHECK "d20aa6b4f5683b7b0040676547997be0" #define IP_PORT_UNION_VERSION (1) /* �Ƿ�IP-PORT�ϲ� */ -#define COMPAT_PAPP_FOR_BENCHMARK (0) /* 2015-01-07 lijia add, ͬpapp�ԱȽ��ʱ, ��ʱ�ر�Ƕ�ס���������Э��, ����һ�� */ -#define USE_RBTREE_INSTEAD_LIST (0) /* ��HASH��ͻʱ, ʹ�ú������������, ������������±��� */ +#define COMPAT_PAPP_FOR_BENCHMARK (0) /* 2015-01-07 lijia add, ͬpapp�ԱȽ���?, ��ʱ�ر�Ƕ�ס���������Э��, ����һ�� */ +#define USE_RBTREE_INSTEAD_LIST (0) /* ��HASH��ͻʱ, ʹ�ú������������?, ������������±���? */ //#define USE_LINUX_KERNEL_HASH_ALGO (1) /* ʹ��LINUX�ں�HASH�㷨 */ #define SAPP_INSECTICIDE (0) /* ɱ��(DEBUG)��ʱ����, ������Ī�������BUGʱ��ʱ����, ���緢������, �����糬�� */ @@ -28,7 +28,7 @@ #define PCAP_CAP_FROM_IP (0) /* Ϊ��ģ��pag��������, ��pcapҲģ���IPv4ͷ����ʼ��ȡ */ -//#define NON_PKT_THREAD_SEND_QUEUE (64) /* �����������߳�����Ͷ������� */ +//#define NON_PKT_THREAD_SEND_QUEUE (64) /* �����������߳�����Ͷ�������? */ #define IKNOW_ENABLE (0) @@ -50,10 +50,13 @@ #define sapp_get_struct_header(ptr, type, member) container_of(ptr, type, member) -#define RAW_PKT_MAGIC_NUM (0xF1E2D3C4) /* 1:���ڼ��ݾ���Ŀ, ��call_old��������ݽṹʱ,ʶ��ԭʼ������Դ; 2:��ȫ�Լ�� */ +#define RAW_PKT_MAGIC_NUM (0xF1E2D3C4) /* 1:���ڼ��ݾ���Ŀ, ��call_old��������ݽṹ�?,ʶ��ԭʼ������Դ; 2:��ȫ�Լ��? */ #define SAPP_DESTROY_DONE_FLAG (0x7FFFFFFF) +#ifndef uuid_t +typedef unsigned char uuid_t[16]; +#endif #ifdef __cplusplus extern "C" { @@ -84,13 +87,13 @@ typedef struct { const void *__lib_raw_pkt_data; /* �ײ㲶�����ṩ����ʵԭʼ��ָ�� */ const void *raw_pkt_data; /* ���ϲ�Ӧ�ÿ���ԭʼ��ͷָ��, �п���������Ethernet��, ����low_layer_type�ж�Э������ */ - struct timeval raw_pkt_ts; /* ԭʼ������ʱ���, ���ȫΪ0��֧�ִ˹���(��pagģʽ) */ + struct timeval raw_pkt_ts; /* ԭʼ������ʱ���?, ���ȫ�?0��֧�ִ˹���(��pagģʽ) */ //2*8 Bytes - const void *io_lib_pkt_reference; /* ���õײ�I/O���ԭʼ�������ṹ, ����:����marsio��˵, ���ײ��mbuf�ṹ */ + const void *io_lib_pkt_reference; /* ���õײ�I/O���ԭʼ��������?, ����:����marsio��˵, ���ײ��mbuf�ṹ */ /* ---8 bytes-- */ int payload_len; /* ���س��� */ - int device_index;/* �ж������ʱ, Ҫ��֤���ĸ������ʹ��ĸ����� */ + int device_index;/* �ж�������?, Ҫ��֤���ĸ������ʹ��ĸ����� */ /* ===8 bytes=== */ /* ---8 bytes-- */ @@ -98,7 +101,7 @@ typedef struct { unsigned char is_overlay_pkt:1; /* ��ʾ����ʵ��·�е����ݰ�, Ҫ��������ע, ��������������һ������; ����Ҫ���� */ unsigned char is_ctrl_pkt:1; unsigned char diagnose_error_to_dump:1; /* ��ij�ִ������ݰ�, ����pkt_dump�洢��udp socket����tcpdump_mesa */ - unsigned char drop_current_pkt_flag:1; /* �������MSO_DROP_CURRENT_PKT���ö�����ǰ��, ÿ�δ�����Ҫ��� */ + unsigned char drop_current_pkt_flag:1; /* �������MSO_DROP_CURRENT_PKT���ö�����ǰ��, ÿ�δ�����Ҫ���? */ unsigned char mac_flipping_enable:1; unsigned char padding_flags:2; //1 Bytes @@ -151,8 +154,8 @@ struct buf_unorder unsigned char ip_reassemble_pkt; UINT32 seq; UINT32 ack; - raw_ipfrag_list_t *ipfrag_list; /* �����ǰ����IP��Ƭ����İ�, ��Ҫ�洢����IP��Ƭ������ */ - raw_pkt_t raw_pkt; /* ������洢ԭʼ�� */ + raw_ipfrag_list_t *ipfrag_list; /* �����ǰ����IP��Ƭ����İ�?, ��Ҫ�洢����IP��Ƭ������ */ + raw_pkt_t raw_pkt; /* ������洢ԭʼ��? */ }; /*�����ṹ�嶨�壺*/ @@ -160,13 +163,13 @@ struct half_tcpstream { UCHAR *data; UINT32 offset; /*data�е�һ���ֽ���TCP�������е�ƫ����*/ - UINT32 count; /*�����ӽ���������Ϊֹ������������ܳ����ֽ���*/ + UINT32 count; /*�����ӽ���������Ϊֹ������������ܳ����ֽ���?*/ UINT32 count_new; /*�����µ��������ֽ���*/ - UINT32 count_ideal; /*�����ӽ���������Ϊֹ��������Ӧ�õ���������ܳ���*/ - UINT32 pktcout; /*�����ۼƵ���İ�����, �����ش���, ACK, ������SYN */ + UINT32 count_ideal; /*�����ӽ���������Ϊֹ��������Ӧ�õ���������ܳ���?*/ + UINT32 pktcout; /*�����ۼƵ���İ�����?, �����ش���, ACK, ������SYN */ UINT32 totallost; /*�����ۼƶ�������*/ - UINT32 seq; /*���������ڴ���seq���*/ - UINT32 first_data_seq; /*����������ʼ�ĵ�seq���*/ + UINT32 seq; /*���������ڴ���seq���?*/ + UINT32 first_data_seq; /*����������ʼ�ĵ�seq���?*/ //UINT32 ack_seq; /*�����������ʹ�õ�Ӧ���, 2017-08-02 lijia modify , �ƶ���struct tcpdetail_private */ @@ -175,11 +178,11 @@ struct half_tcpstream UCHAR finstate; /*fin״̬*/ UINT16 unorder_cnt;/* 2014-11-27 lijia modify, ijЩ����������, UCHAR�Ͳ���, ��չΪUINT16 */ UINT16 maxunorder; /* 2014-11-27 lijia modify, ijЩ����������, UCHAR�Ͳ���, ��չΪUINT16 */ - struct buf_unorder *unorderlist; /*�����������*/ - struct buf_unorder *unorderlisttail; /*�����������β��ָ��*/ + struct buf_unorder *unorderlist; /*�����������?*/ + struct buf_unorder *unorderlisttail; /*�����������β��ָ��?*/ }; -/* ����ÿ�������������һ����, ����polling entry����ʹ�� */ +/* ����ÿ�������������һ����?, ����polling entry����ʹ�� */ typedef struct { const raw_pkt_t *raw_pkt_stream_dir[2]; struct rawpkt_metadata* meta_stream_dir[2];// ÿ������metadata��[0:c2s, 1:s2c]����洢��polling_inject_context��, update_raw_pkt��������ʱ����������䵽���ص�rawpkt�� @@ -187,32 +190,32 @@ typedef struct { struct streaminfo_private { - /* ����ṹ�����ڽṹ����ǰ, ָ���ַ���Ի���ǿת */ + /* ����ṹ�����ڽṹ�����?, ָ���ַ���Ի���ǿ�? */ struct streaminfo stream_public; - struct streaminfo_private *pfather_pr; /* ��ʵ�������ϲ���ָ��, ������vxlan�ȷ�װ��, stream_public.pfather�Ǹ�ҵ��������,������vxlan��� */ + struct streaminfo_private *pfather_pr; /* ��ʵ�������ϲ���ָ��, ������vxlan�ȷ�װ��, stream_public.pfather�Ǹ�ҵ��������,������vxlan���? */ /* ���±���Ϊƽ̨�ڲ�˽��, ���ⲻ�ɼ� */ void *cur_plugin_cb_func; void *pproject; //ÿ�����̿����Զ���ʹ�ã� /* ---8 bytes-- */ - UCHAR layer_dir:2; /* ������Ч, ��ǰ��ĵ�ַ�Ƿ��Ĭ�Ϲ���"��˿��ǿͻ���"��ͬ */ - UCHAR stream_dir:1; /* ��������������Ч, ���Ĵ洢�ĵ�ַ�Ƿ��Ĭ�Ϲ���"��˿��ǿͻ���"��ͬ */ - UCHAR stream_c2s_route_dir:1; /* c2s����İ�, ��Ӧ����·route dir����, ���ڻ�ȡinbound, outbound���� */ - UCHAR addr_use_as_hash:1; /* �����addr�Ƿ���ΪHASH����ͱȽϵIJ���, ��:MAC��ַ��������� */ + UCHAR layer_dir:2; /* ������Ч, ��ǰ��ĵ�ַ�Ƿ��Ĭ�Ϲ���"��˿��ǿͻ���?"��ͬ */ + UCHAR stream_dir:1; /* ��������������Ч, ���Ĵ洢�ĵ�ַ�Ƿ��Ĭ�Ϲ���?"��˿��ǿͻ���?"��ͬ */ + UCHAR stream_c2s_route_dir:1; /* c2s����İ�?, ��Ӧ����·route dir����, ���ڻ�ȡinbound, outbound���� */ + UCHAR addr_use_as_hash:1; /* �����addr�Ƿ���ΪHASH����ͱȽϵIJ���?, ��:MAC��ַ���������? */ UCHAR set_special_timeout:1; UCHAR need_update_opposite_addr:1;/*�����addr�Ƿ��ڶԲ�����ʱ���£��磺MPLS��ǩ�ǶԳ�ʱ��Ҫ��S2C���һ������¼�����ǩ,��ֵĬ��Ϊ0��������Ҫ����*/ UCHAR stream_killed_flag:1; /* 2014-08-22 lijia add, ����ģʽ��, �Ѿ������Kill, ֮�������ֱ��Drop��Kill, �����ٸ��ϲ��� */ - UCHAR dirreverse; /* ��������ʱ�Ƿ������ip��ַ��ת, ����"��˿��ǿͻ���"�����෴ */ - UINT16 timeout;/* ÿ�����ӵĶ��г�ʱʱ��, ��ֵ��������;, 1:���ھ�����̭��ʱ���ް��������, �Խ�Լ�ڴ�; 2:���ڱ�����ʱ���ް�����, ����IM�ʱ���ް������Ӳ�δ����, �����ýϴ��timeout */ - unsigned short offset_to_raw_pkt_hdr; /* ����ͷ�����ԭʼ������ʼ��ַ��ƫ���� */ + UCHAR dirreverse; /* ��������ʱ�Ƿ������ip��ַ��ת, ����"��˿��ǿͻ���?"�����෴ */ + UINT16 timeout;/* ÿ�����ӵĶ��г�ʱʱ��, ��ֵ��������;, 1:���ھ�����̭��ʱ���ް��������?, �Խ�Լ�ڴ�; 2:���ڱ�����ʱ���ް�����, ����IM�ʱ���ް������Ӳ�δ����, �����ýϴ��timeout */ + unsigned short offset_to_raw_pkt_hdr; /* ����ͷ�����ԭʼ������ʼ��ַ��ƫ����? */ unsigned short offset_to_ip_hdr; /* 2015-12-07 lijia add, UDP/TCP ��ͷ����ڳ��ص�IP��ͷƫ���� */ /* ===8 bytes=== */ const raw_pkt_t *raw_pkt; /* 2014-12-30 lijia add, ��Щ�ص�������֧��ԭʼ��, ����������Ҫ, �洢��private�ṹ�� */ /* ---8 bytes-- */ - unsigned int hash_slave; /* 2015-12-14 lijia add, ʹ��linux_jhash����ʱ, ����ͬʱ�õ��������ϵ�HASHֵ, ��HASH����ȷ����HASH����SLOTλ��, slave_HASH���ڿ��ٱȽϵ�ַ�Ƿ���� */ + unsigned int hash_slave; /* 2015-12-14 lijia add, ʹ��linux_jhash����ʱ, ����ͬʱ�õ��������ϵ�HASHֵ, ��HASH����ȷ����HASH����SLOTλ��, slave_HASH���ڿ��ٱȽϵ�ַ�Ƿ����? */ unsigned char hash_not_head_times;/* 2015-12-15 lijia add, ��ǰindex����HASH SLOT�ĵ�һλ�Ĵ��� */ - unsigned char cur_layer_raw_hdr_len; /* 2017-10-31 lijia add, ��ǰ���ԭʼ����ַ����, ��pppͷ��ѹ��, ԭ���汾���������״̬, ����ʱҲ����֪��ַ������ */ + unsigned char cur_layer_raw_hdr_len; /* 2017-10-31 lijia add, ��ǰ���ԭʼ����ַ����?, ��pppͷ��ѹ��, ԭ���汾���������״�?, ����ʱҲ����֪��ַ������ */ unsigned char __pad:1; unsigned char packet_process_context:1; unsigned char is_ctrl_pkt:1; @@ -222,8 +225,8 @@ struct streaminfo_private /* ===8 bytes=== */ /* ---8 bytes-- */ - unsigned short stream_low_layer_tunnel_type; /* 2016-07-25 lijia add, ��¼�����ײ���������, 0Ϊ������, �������:enum stream_carry_tunnel_t */ - unsigned short stream_carry_up_layer_tunnel_type; /* ��ǰ���ϲ����������, ���統ǰ��ΪUDP, ���صĿ�����teredo������L2TP���� */ + unsigned short stream_low_layer_tunnel_type; /* 2016-07-25 lijia add, ��¼�����ײ���������, 0Ϊ������, �������?:enum stream_carry_tunnel_t */ + unsigned short stream_carry_up_layer_tunnel_type; /* ��ǰ���ϲ����������?, ���統ǰ��ΪUDP, ���صĿ�����teredo������L2TP���� */ /* 2016-07-08 lijia add, for janus hijack, ��Ӧ�ô洢��half_stream, �����յ�SYNʱ, ��û�д���half_streamʵ��, �����ݴ���streaminfo_private */ unsigned short syn_opt_num; unsigned short synack_opt_num; @@ -247,10 +250,10 @@ struct streaminfo_private unsigned long long stream_create_timestamp_ms; unsigned long long stream_lastupdate_timestamp_ms; /* ---8 bytes-- */ - unsigned char layer_index:4; /* ��ʾ��ǰ��ļ���, ����ײ㿪ʼ,һ����ethernet��ʼ, ��0��ʼ����, 4bit���֧��15��Ƕ��, Ҳ�ܷ�ֹ����Ƕ����(Ŀǰ��û��������) */ - unsigned char create_dir_by_well_known_port:1; /* UDP��TCP��data������, ����well_known_port����, �����ǰ���˿��ǿͻ���ԭ���� */ + unsigned char layer_index:4; /* ��ʾ��ǰ��ļ���?, ����ײ㿪�?,һ����ethernet��ʼ, ��0��ʼ����, 4bit���֧��?15��Ƕ��, Ҳ�ܷ�ֹ����Ƕ����(Ŀǰ��û��������) */ + unsigned char create_dir_by_well_known_port:1; /* UDP��TCP��data������, ����well_known_port����, �����ǰ���˿��ǿͻ���ԭ����? */ char __pad2:3; - char has_duplicate_pkt; /* ��ǰ�������й��ظ����ݰ�, ����������Ӧ��ÿ������� */ + char has_duplicate_pkt; /* ��ǰ�������й��ظ����ݰ�, ����������Ӧ��ÿ�������? */ char under_ddos_bypass; char __pad3[3]; /* ===8 bytes=== */ @@ -258,11 +261,12 @@ struct streaminfo_private unsigned char ip_ttl_c2s; unsigned char ip_ttl_s2c; void *stream_bridge; /* 20210425 lijia add, ����project����, ֧��ͬ�����첽����ģʽ, ԭ��project�����첽ģʽ */ + uuid_t stream_uuid; }; struct tcpdetail_private { - /* ����ṹ�����ڽṹ����ǰ, ָ���ַ���Ի���ǿת */ + /* ����ṹ�����ڽṹ�����?, ָ���ַ���Ի���ǿ�? */ struct tcpdetail tcpdetail_public; /* ---8 bytes-- */ @@ -273,7 +277,7 @@ struct tcpdetail_private UCHAR needackflag:1; //��Ҫ�ϴ�ack���� UCHAR takeoverflag:1; UCHAR has_lost_pkt_flag:1; //2020-08-23 lijia add, ����������������־λ - UCHAR tcpstateflag; // ���ڼ�¼tcp�ĻỰSYN���״̬ + UCHAR tcpstateflag; // ���ڼ�¼tcp�ĻỰSYN���״�? UCHAR link_state; // ���ӵ�״̬ UCHAR creat_mod; UINT16 tcpoverlen; // modify by lqy 20150225, ��¼��ǰ������һ�������ص�tcp���ȣ� @@ -288,18 +292,18 @@ struct tcpdetail_private UINT32 iclientseq; //���ӽ���ʱ��ʱ�洢seq, ��ֵ��S2C->SYN+1 /* NOTE: Ϊ��first_ack_seq������half_tcpstream��? - ��half_tcpstream�����յ���һ�����и��صİ��ŷ����, + ��half_tcpstream�����յ���һ�����и��صİ��ŷ����?, �����tcp_deal_ack()����������, �����S2C����, ��ô��һ��S2C���ݰ�����ʱ, �Ѿ�����first_ack_seq��. �����Է�ֹDDOS����. */ - UINT32 C2S_first_ack_seq; /* 2017-08-02 lijia modify, C2S���һ��ACK��, ��half_tcpstream->ack_seqһ����Լ�����������Բ���������� */ + UINT32 C2S_first_ack_seq; /* 2017-08-02 lijia modify, C2S���һ��ACK��, ��half_tcpstream->ack_seqһ����Լ�����������Բ����������? */ UINT32 C2S_ack_seq; /* 2017-08-02 lijia add, C2S�൱ǰ��ACK�� */ - UINT32 S2C_first_ack_seq; /* 2017-08-02 lijia modify, C2S���һ��ACK��, ��half_tcpstream->ack_seqһ����Լ�����������Բ���������� */ + UINT32 S2C_first_ack_seq; /* 2017-08-02 lijia modify, C2S���һ��ACK��, ��half_tcpstream->ack_seqһ����Լ�����������Բ����������? */ UINT32 S2C_ack_seq; /* 2017-08-02 lijia add, S2C�൱ǰ��ACK�� */ void *apme; //Ӧ�ò������� void *pAllpktpme; //��״̬��tcp���������� - struct tcp_flow_stat *flow_stat; /* 2016-07-14 lijia add, ���ڼ�¼TCP��data���ļ���, ʵ���ڴ������ͷ���projectģ�����, ����ΪNULL, */ - struct tcp_flow_stat *deduce_flow_stat; /* 2018-10-30 lijia add, ���ڼ�¼������ƶϳ������ϴ��������, ���������ij���; �Լ������������, �Զ�Ӧ���յ������� */ + struct tcp_flow_stat *flow_stat; /* 2016-07-14 lijia add, ���ڼ�¼TCP��data���ļ���, ʵ���ڴ������ͷ���projectģ�����?, ����ΪNULL, */ + struct tcp_flow_stat *deduce_flow_stat; /* 2018-10-30 lijia add, ���ڼ�¼������ƶϳ������ϴ��������, ���������ij���; �Լ������������?, �Զ�Ӧ���յ������� */ unsigned short rtt_csc; unsigned short rtt_scs; long long last_c2s_pkt_rcv_time; @@ -308,10 +312,10 @@ struct tcpdetail_private struct udpdetail_private { - /* ����ṹ�����ڽṹ����ǰ, ָ���ַ���Ի���ǿת */ + /* ����ṹ�����ڽṹ�����?, ָ���ַ���Ի���ǿ�? */ struct udpdetail udpdetail_public; void *apme; //Ӧ�ò������� - struct udp_flow_stat *flow_stat; /* 2015-12-28 lijia add, udpdetail�е���ϸ����(64bit), ʵ���ڴ������ͷ���projectģ�����, ����ΪNULL */ + struct udp_flow_stat *flow_stat; /* 2015-12-28 lijia add, udpdetail�е���ϸ����(64bit), ʵ���ڴ������ͷ���projectģ�����?, ����ΪNULL */ UCHAR drop_stream_flag; //2020-06-02 lijia add, ����ͬDROPPKT, ֻ����������������stream UCHAR offload_stream_flag; //2022-04-13 liuxueli add, ������������stream UCHAR pad[6]; @@ -321,7 +325,7 @@ struct udpdetail_private /* 2015-02-26 lijia add, for stream-addr-list ntop, pton */ typedef struct{ struct streaminfo stream; - char addr_value[MAX_ADDR_BIN_VALUE_LEN]; /* Ϊ��paddr������malloc, �������, ��stream������һ�黺�� */ + char addr_value[MAX_ADDR_BIN_VALUE_LEN]; /* Ϊ��paddr������malloc, �������?, ��stream������һ�黺�� */ }addr_continuous_bin_t; typedef struct{ @@ -340,15 +344,15 @@ struct pptp_stream_key{ UINT32 dip; /* sip,dip are network order */ UINT16 sip_side_call_id; /* �������ݰ�����sip������GRE����callid, ʵ�������ʾpeer call id, network order */ UINT16 dip_side_call_id; /* �������ݰ�����dip������GRE����callid, ʵ�������ʾpeer call id, network order */ - //struct streaminfo_private *stream_pr; /* TODO 1, ���ڱ����ַ����, Ŀǰ��������ײ��IP��call_id */ + //struct streaminfo_private *stream_pr; /* TODO 1, ���ڱ����ַ����?, Ŀǰ��������ײ��IP��call_id */ }; /* PPTPЭ�����������ṹ, sapp�ڲ�ʹ�� */ struct pptp_info_pri{ struct MESA_tunnel_info tunnel_context; struct pptp_stream_key pptp_key; - stSessionInfo ssinfo; /* ����ҵ�����������Ϣ */ - void *biz_pme; /* ҵ����Զ������� */ + stSessionInfo ssinfo; /* ����ҵ������������? */ + void *biz_pme; /* ҵ����Զ�������? */ struct streaminfo *my_stream; /* pptp�ײ�UDP�� */ unsigned char threadnum; char insert_hash_flag; /* ���������ѽ�key����HASH�� */ @@ -370,13 +374,13 @@ struct l2tp_stream_key{ UINT16 sip_side_session_id; /* sip�ⷢ������tunnelid, network order */ UINT16 dip_side_tunnel_id; /* dip�ⷢ������tunnelid, network order */ UINT16 dip_side_session_id; /* dip�ⷢ������tunnelid, network order */ - //struct streaminfo_private *stream_pr; /* TODO 1, ���ڱ����ַ����, Ŀǰ��������ײ��IP��call_id */ + //struct streaminfo_private *stream_pr; /* TODO 1, ���ڱ����ַ����?, Ŀǰ��������ײ��IP��call_id */ }; struct l2tp_info_pri{ struct MESA_tunnel_info tunnel_context; struct l2tp_stream_key l2tp_key; - stSessionInfo ssinfo; /* ����ҵ��������� */ + stSessionInfo ssinfo; /* ����ҵ���������? */ void *biz_pme; const struct streaminfo *my_stream; /* l2tp�ײ�UDP�� */ unsigned char thread_seq; @@ -386,13 +390,13 @@ struct l2tp_info_pri{ #define STATSD_SEND_MSS (1472) /* ȫ��Ψһ��ȫ�ֱ���, ͨ���ǿ�����������, ���仯��ȫ�ֱ���, ����������, ������ֻ�� */ struct sapp_global_single_t{ - int signal_take_over_sw; /* �Ƿ�ӹܳ���ϵͳ�ź�, ��SIGSEGV, SIGABRT�ȵ� */ + int signal_take_over_sw; /* �Ƿ�ӹܳ���ϵͳ�ź�?, ��SIGSEGV, SIGABRT�ȵ� */ int ipentry_priority_over_ipfrag; /* IP_entry���ȼ�����IP_frag_entry, Ĭ��Ϊ0, ��ӦWY�����ض����� */ //int kill_tcp_with_gdev; /* FDδ��Чʱ, ����gdev�������� */ int cfg_send_tcp_offload_sw; /* ��������MTUʱ, ������Ƭ�ɶ��С��MTU�İ����� */ //int cfg_kill_tcp_rst_num; /* kill_tcp����rst������ */ //int cfg_kill_tcp_rst_signature; /* kill_tcp���͵�rst�Ƿ���Ҫָ����Ϣ, ����ʶ�� */ - //int tuple4_reuse_time_interval; /* ��Ԫ�����õ���С���ʱ�� */ + //int tuple4_reuse_time_interval; /* ��Ԫ�����õ���С���ʱ��? */ //void *fs2_handle; const char *fs2_server_ip; unsigned short fs2_server_port_host; @@ -404,9 +408,9 @@ struct sapp_global_single_t{ }; #define TIMESTAMP_SINGLE_PKT_REGION (4) /* ������ʱͳ������ */ -#define TIMESTAMP_SINGLE_PKT_REGION_MAX (5) /* ��������ͳ�������ֵ */ +#define TIMESTAMP_SINGLE_PKT_REGION_MAX (5) /* ��������ͳ��������? */ typedef struct{ - unsigned int runtime_pkt_max_delay; /* �����������ʱ */ + unsigned int runtime_pkt_max_delay; /* ������������? */ unsigned long long pkt_total_num[TIMESTAMP_SINGLE_PKT_REGION_MAX]; /* ��¼��������ʱ���ܰ���, ������ͳ�� */ unsigned long long pkt_total_time; /* ���һ��ʱ�������ʱ, ���ڼ���ƽ������������ʱ */ }timestamp_record_region_t; @@ -420,15 +424,15 @@ struct sapp_global_mthread_t{ char __pad1[4]; double pptp_hash_avg_search_times; double l2tp_hash_avg_search_times; - int tcp_stream_special_timeout_num; /* ���õ�����ʱʱ�����, Ĭ�ϲ�����������������10% */ - int udp_stream_special_timeout_num;/* ���õ�����ʱʱ�����, Ĭ�ϲ�����������������10% */ + int tcp_stream_special_timeout_num; /* ���õ�����ʱʱ�����?, Ĭ�ϲ�����������������10% */ + int udp_stream_special_timeout_num;/* ���õ�����ʱʱ�����?, Ĭ�ϲ�����������������10% */ timestamp_record_region_t runtime_record; timestamp_record_region_t runtime_record_driver; /* �����������õ���, ��ƽ̨�õ�������ʱ */ }__attribute__ ((aligned (64))); typedef struct{ #ifdef DEBUG - unsigned int magic; /* malloc�����0x4D4D4D4D, ��MMMM ��16����; free�����0xFEFEFEFE */ + unsigned int magic; /* malloc�����?0x4D4D4D4D, ��MMMM ��16����; free�����?0xFEFEFEFE */ #endif unsigned int user_buf_size; }sapp_private_mem_t; diff --git a/include/public/stream_inc/stream_control.h b/include/public/stream_inc/stream_control.h index 0f7ec24..4353f70 100644 --- a/include/public/stream_inc/stream_control.h +++ b/include/public/stream_inc/stream_control.h @@ -1,386 +1,389 @@ #ifndef _APP_STREAM_CONTROL_H_
-#define _APP_STREAM_CONTROL_H_
+#define _APP_STREAM_CONTROL_H_
#ifdef __cplusplus
-extern "C" {
+extern "C"
+{
#endif
-#define STREAM_CONTROL_H_VERSION (20210818)
-
-#define TCP_CTEAT_LINK_BYSYN 0x01 /* for MESA_stream_opt->MSO_TCP_CREATE_LINK_MODE */
-#define TCP_CTEAT_LINK_BYDATA 0x02 /* for MESA_stream_opt->MSO_TCP_CREATE_LINK_MODE */
-
-/*
- option of stream,
-
- MSO_IGNORE_RST_FIN: will not be terminated by RST, FIN packet, only if timeout or in LRU tail, it will be eliminated.
-*/
-enum MESA_stream_opt{
- __MSO_PAD = 0, /* placeholder */
- MSO_MAX_UNORDER = 1, /* opt_val type must be struct max_unorder_opt */
- MSO_NEED_ACK, /* opt_val type must be unsigned char, value only be [0,1] */
- MSO_TAKEOVER, /* opt_val type must be int, value only be [0,1] */
- MSO_TIMEOUT, /* opt_val type must be unsigned short */
- MSO_IGNORE_RST_FIN, /* opt_val type must be unsigned char, value only be [0,1] */
- MSO_TCP_CREATE_LINK_MODE, /* opt_val must be unsigned char, refer to TCP_CTEAT_LINK_xxx */
- MSO_TCP_ISN_C2S, /* Host-order, opt_val type must be unsigned int */
- MSO_TCP_ISN_S2C, /* Host-order, opt_val type must be unsigned int */
- MSO_TCP_SYN_OPT, /* opt_val must be struct tcp_option **, opt_val_len [OUT} is struct tcp_option number, valid only if SYN packet is captured */
- MSO_TCP_SYNACK_OPT, /* opt_val must be struct tcp_option **, opt_val_len [OUT} is struct tcp_option number, valid only if SYN/ACK packet is captured */
- MSO_STREAM_TUNNEL_TYPE, /* opt_val must be unsigned short, refer to enum stream_carry_tunnel_t */
- MSO_STREAM_CLOSE_REASON, /* opt_val type must be unsigned char, refer to stream_close_reason_t */
- MSO_STREAM_VXLAN_INFO, /* opt_val type must be struct vxlan_info, only support for MAC-in-MAC encapsulation in mirror mode */
- MSO_TCPALL_VALID_AFTER_KILL, /* opt_val type must be unsigned char, value only be [0,1]; Warning, this option is obsolete, use MESA_rst_tcp() instead */
- MSO_GLOBAL_STREAM_ID, /* opt_val type must be unsigned long long, is value-result argument, IN: device_id, value range[0, 4095]; OUT:global stream id */
- MSO_DROP_STREAM, /* opt_val type must be int, value only be [0,1]; similar to DROPPKT, but effective scope is all subsequent packets of this stream. */
- MSO_TCP_RST_REMEDY, /* opt_val type must be int, value only be [0,1]; if not set this, default is disable. */
- MSO_TOTAL_INBOUND_PKT, /* inbound packet number of this stream, opt_val type must be unsigned long long */
- MSO_TOTAL_INBOUND_BYTE, /* inbound packet byte of this stream, opt_val type must be unsigned long long */
- MSO_TOTAL_OUTBOUND_PKT, /* outbound packet pkt of this stream, opt_val type must be unsigned long long */
- MSO_TOTAL_OUTBOUND_BYTE,/* outbound packet byte of this stream, opt_val type must be unsigned long long */
- MSO_STREAM_CREATE_TIMESTAMP_MS,/* first pkt arrive timestamp of this stream, opt_val type must be unsigned long long */
- MSO_TOTAL_INBOUND_BYTE_RAW, /* inbound packet byte of this stream, raw packet len, include ip hdr, ethernet hdr... opt_val type must be unsigned long long */
- MSO_TOTAL_OUTBOUND_BYTE_RAW,/* outbound packet byte of this stream, raw packet len, include ip hdr, ethernet hdr... opt_val type must be unsigned long long */
- MSO_STREAM_UP_LAYER_TUNNEL_TYPE, /* opt_val must be unsigned short, refer to enum stream_carry_tunnel_t */
- MSO_STREAM_PLUG_PME, /* opt_val type must be struct mso_plug_pme, this is a value-result argument, the caller should set plug_name and plug_entry_type, only support: TCP, TCP_ALL, UDP */
- MSO_DROP_CURRENT_PKT, /* opt_val type must be int, value only be [0,1], notice the difference between MSO_DROP_CURRENT_PKT and MSO_DROP_STREAM, MSO_DROP_CURRENT_PKT only discard current packet, but MSO_DROP_STREAM discard all subsequent packets of stream */
- MSO_HAVE_DUP_PKT, /* opt_val type must be int, value only be [0, 1, -2], if the current stream found duplicate packets ? 0:no; 1:yes; -2: not sure */
- MSO_STREAM_LASTUPDATE_TIMESTAMP_MS,/* latest pkt arrive timestamp of this stream, opt_val type must be unsigned long long */
- MSO_STREAM_TIMED,
- MSO_STREAM_APPLEND_SEGMENT_ID_LIST,
- MSO_STREAM_PREPLEND_SEGMENT_ID_LIST,
- MSO_STREAM_SET_DATAMETA_TRACE_ID,
- MSO_STREAM_C2S_RAWPKT_HDR,
- MSO_STREAM_S2C_RAWPKT_HDR,
- MSO_STREAM_C2S_SYN_NUM,
- MSO_STREAM_S2C_SYN_NUM,
- MSO_STREAM_INBOND_LINK_ID,
- MSO_STREAM_OUTBOND_LINK_ID,
- MSO_STREAM_C2S_ROUTE_DIRECTION,
- MSO_STREAM_INBOND_ROUTE_CTX,
- MSO_STREAM_OUTBOND_ROUTE_CTX,
- MSO_STREAM_C2S_LINK_ID,
- MSO_STREAM_S2C_LINK_ID,
- MSO_STREAM_C2S_ROUTE_CTX,
- MSO_STREAM_S2C_ROUTE_CTX,
- MSO_IP_TTL_C2S, /* opt_val type must be unsigned char, IPv4 is TTL, IPv6 is Hop Limit */
- MSO_IP_TTL_S2C, /* opt_val type must be unsigned char, IPv4 is TTL, IPv6 is Hop Limit */
- MSO_TCP_RTT_CSC, /* opt_val type must be unsigned short, the full RTT is client->tsg->server->tsg->client, this is |tsg->server->tsg| */
- MSO_TCP_RTT_SCS, /* opt_val type must be unsigned short, the full RTT is server->tsg->client->tsg->server, this is |tsg->client->tsg| */
- MSO_STREAM_C2S_SEGMENT_ID_LIST,
- MSO_STREAM_S2C_SEGMENT_ID_LIST,
- MSO_STREAM_INBOND_SEGMENT_ID_LIST,
- MSO_STREAM_OUTBOND_SEGMENT_ID_LIST,
- __MSO_MAX,
-};
-
-/* for MSO_STREAM_CLOSE_REASON,
- don't confuse, these values is not consecutive indeed, because some value(1,2) is obsoleted!
-*/
-enum stream_close_reason_t{
- STREAM_CLOSE_REASON_SYN_REUSE = 0, /* for TCP tuple4 reuse */
- STREAM_CLOSE_REASON_NORMAL = 3, /* for TCP FIN, FIN/ACK */
- STREAM_CLOSE_REASON_RESET = 4, /* for TCP RESET */
- STREAM_CLOSE_REASON_TIMEOUT = 5, /* timeout */
- STREAM_CLOSE_REASON_LRUOUT = 6, /* stream table full, kick out */
- STREAM_CLOSE_REASON_DEPRIVE = 7, /* deprive by some plug who return KILL_FOLLOW or KILL_OTHER */
- STREAM_CLOSE_REASON_DUMPFILE = 8, /* only for pcap dumpfile mode */
-};
-
-
-enum sapp_platform_opt{
- SPO_TOTAL_RCV_PKT, /* total recv packet number, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_BYTE, /* total recv packet byte, opt_val type must be unsigned long long */
- SPO_REALTIME_RCV_PKT, /* realtime recv packet number, opt_val type must be unsigned long long */
- SPO_REALTIME_RCV_BYTE, /* realtime recv packet byte, opt_val type must be unsigned long long */
- SPO_THREAD_COUNT, /* total thread count, opt_val type must be int */
- SPO_CURTIME_TIMET, /* current time, opt_val type must be time_t */
- SPO_CURTIME_STRING, /* current time, opt_val type must be char[], opt_val_len must more than strlen("1970-01-01 01:01:01") */
- SPO_START_TIME, /* platform start time, opt_val type must be time_t */
- SPO_RUN_TIME, /* platform running time, opt_val type must be time_t */
- SPO_RAND_NUMBER, /* get a rand number, opt_val type must be long long */
- SPO_FIELD_STAT_HANDLE, /* field stat output handle, opt_val type must be void * */
- SPO_INDEPENDENT_THREAD_ID, /* plug independent thread which is created by pthread_create(), opt_val type must be int */
- SPO_DEPLOYMENT_MODE_STR, /* opt_val type is char[], optional value is:["mirror", "inline", "transparent"] */
- SPO_TCP_STREAM_NEW, /* total created tcp streams from start, opt_val type must be unsigned long long */
- SPO_TCP_STREAM_CLOSE, /* total closed tcp streams from start, opt_val type must be unsigned long long */
- SPO_TCP_STREAM_ESTAB, /* realtime established tcp streams, opt_val type must be unsigned long long */
- SPO_TOTAL_INBOUND_PKT, /* total inbound packet number, opt_val type must be unsigned long long */
- SPO_TOTAL_INBOUND_BYTE, /* total inbound packet bytes, opt_val type must be unsigned long long */
- SPO_TOTAL_OUTBOUND_PKT, /* total outbound packet number, opt_val type must be unsigned long long */
- SPO_TOTAL_OUTBOUND_BYTE, /* total outbound packet bytes, opt_val type must be unsigned long long */
- SPO_UDP_STREAM_NEW, /* total created udp streams from start, opt_val type must be unsigned long long */
- SPO_UDP_STREAM_CLOSE, /* total closed udp streams from start, opt_val type must be unsigned long long */
- SPO_UDP_STREAM_CONCURRENT, /* realtime Concurrent udp streams, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_INBOUND_IPV4_PKT, /* total recv ipv4 packet number, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_INBOUND_IPV4_BYTE, /* total recv ipv4 packet number, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_OUTBOUND_IPV4_PKT, /* total recv ipv4 packet bytes, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_OUTBOUND_IPV4_BYTE, /* total recv ipv4 packet bytes, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_INBOUND_IPV6_PKT, /* total recv ipv6 packet number, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_INBOUND_IPV6_BYTE, /* total recv ipv6 packet number, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_OUTBOUND_IPV6_PKT, /* total recv ipv6 packet bytes, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_OUTBOUND_IPV6_BYTE, /* total recv ipv6 packet bytes, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_INBOUND_TCP_PKT, /* total recv tcp packet number, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_INBOUND_TCP_BYTE, /* total recv tcp packet number, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_OUTBOUND_TCP_PKT, /* total recv tcp packet bytes, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_OUTBOUND_TCP_BYTE, /* total recv tcp packet bytes, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_INBOUND_UDP_PKT, /* total recv udp packet number, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_INBOUND_UDP_BYTE, /* total recv udp packet number, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_OUTBOUND_UDP_PKT, /* total recv udp packet bytes, opt_val type must be unsigned long long */
- SPO_TOTAL_RCV_OUTBOUND_UDP_BYTE, /* total recv udp packet bytes, opt_val type must be unsigned long long */
- SPO_CURTIME_TIMET_MS, /* current time in millisecond, opt_val type must be long long */
- SPO_CURRENT_STATE, /* running stage of sapp, opt_val type is enum sapp_state_t */
- SPO_CONFIG_ROOT_DIR, /* config file root directory, opt_val type must be char[], opt_val_len is value-result argument */
- SPO_DATA_ROOT_DIR, /* data or state file root directory, opt_val type must be char[], opt_val_len is value-result argument */
- SPO_DEPLOYMENT_MODE, /* Similar to SPO_DEPLOYMENT_MODE_STR, opt_val type is sapp_deploment_mode_t */
- SPO_TCP_STREAM_C2S, /* total number of TCP c2s flows processed since start of run, opt_val type must be unsigned long long */
- SPO_TCP_STREAM_S2C, /* total number of TCP s2c flows processed since start of run, opt_val type must be unsigned long long */
- SPO_TCP_STREAM_DOUBLE, /* total number of TCP bidirectional flows processed since start of run, opt_val type must be unsigned long long */
- SPO_UDP_STREAM_C2S, /* total number of TCP c2s flows processed since start of run, opt_val type must be unsigned long long */
- SPO_UDP_STREAM_S2C, /* total number of TCP s2c flows processed since start of run, opt_val type must be unsigned long long */
- SPO_UDP_STREAM_DOUBLE, /* total number of TCP bidirectional flows processed since start of run, opt_val type must be unsigned long long */
-};
-
-
-/*
- option of device,
-*/
-enum sapp_device_opt{
- __SDO_PAD = 0, /* placeholder */
- SDO_MAC_ADDR, /* device mac addr, opt_val type must be at least char[6] */
- SDO_IPV4_ADDR, /* device ipv4 addr in network order, opt_val type must be int */
- SDO_MTU, /* device MTU, opt_val type must be int */
- __SDO_MAX,
-};
-
-/* for MSO_MAX_UNORDER */
-struct max_unorder_opt{
- unsigned short stream_dir; /* refer to stream_base.h, DIR_C2S, DIR_S2C, DIR_DOUBLE */
- unsigned short max_unorder_val;
-};
-
-
-enum stream_timer_return_value{
- KEEP = 0,
- DROP = 1,
-};
-
-
-#define MAX_TCP_OPT_LEN (38) /* TCP max hdr length 60Bytes, set max opt length 38 Bytes */
-#define MAX_TCP_OPT_NUM (20)
-
-enum tcp_option_value{
- TCP_OPT_EOL = 0,
- TCP_OPT_NOP = 1,
- TCP_OPT_MSS = 2,
- TCP_OPT_WIN_SCALE = 3,
- TCP_OPT_SACK = 4,
- TCP_OPT_SACK_EDGE = 5,
- TCP_OPT_TIME_STAMP = 8, /* refer to struct tcp_option_ts */
- TCP_OPT_MD5 = 19,
- TCP_OPT_MULTI_PATH_TCP = 0x1E,
- TCP_OPT_RIVER_PROBE = 0x4c,
-};
-
-struct tcp_option_ts{
- unsigned int ts_self;
- unsigned int ts_echo_reply;
-};
-
-struct tcp_option{
- unsigned char type;
- unsigned char len; /* pure payload len, not contain type and this len field */
- union{
- unsigned char char_value;
- unsigned short short_value;
- unsigned int int_value;
- unsigned long long long_value;
- char *variable_value;
- struct tcp_option_ts opt_ts_val;
- };
-} __attribute__((packed, aligned(1)));
-
-struct tcp_option_ext{
- unsigned char type;
- unsigned char len;
- union{
- unsigned char char_value;
- unsigned short short_value;
- unsigned int int_value;
- unsigned long long long_value;
- char variable_value[MAX_TCP_OPT_LEN];
- struct tcp_option_ts opt_ts_val;
- };
-} __attribute__((packed, aligned(1)));
-
-
-struct vxlan_info{
- unsigned char encap_type;
- unsigned char entrance_id;
- unsigned char dev_id;
- unsigned char link_id;
- unsigned char link_dir;
- unsigned char inner_smac[18]; /*string, "11:22:33:44:55:66" */
- unsigned char inner_dmac[18]; /* string, "11:22:33:44:55:66" */
- unsigned char inner_smac_hex[6]; /* hex */
- unsigned char inner_dmac_hex[6]; /* hex */
-};
-
-
-enum sapp_state_t{
- SAPP_STATE_JUST_START, /* main() called by shell command */
- SAPP_STATE_CONFIG_PARSE,
- SAPP_STATE_PLATFORM_INITING,
- SAPP_STATE_PLATFORM_INITED, /* 3 */
- SAPP_STATE_PLUG_INITING,
- SAPP_STATE_PLUG_INITED, /* 5 */
- SAPP_STATE_PKT_IO_INITING,
- SAPP_STATE_PKT_IO_INITED,
- SAPP_STATE_PROCESSING, /* 8 */
- SAPP_STATE_READY_TO_EXIT, /* 9, pcap dumpfile mode, or recv custom signal */
- SAPP_STATE_EXIT,
-};
-
-
-struct mso_plug_pme{
- const char *plug_name; /* argument: IN, comes from plug.inf-->[PLUGINFO]-->PLUGNAME */
- const char *plug_entry_type; /* argument: IN, only support: TCP, TCP_ALL, UDP. */
- void *plug_pme; /* argument: OUT, plug private memory address of current stream */
-};
-
-enum sapp_deploment_mode_t{
- DEPLOYMENT_MODE_MIRROR = 1,
- DEPLOYMENT_MODE_TRANSPARENT = 2,
- DEPLOYMENT_MODE_INLINE = 3,
-};
-
+#define STREAM_CONTROL_H_VERSION (20210818)
+
+#define TCP_CTEAT_LINK_BYSYN 0x01 /* for MESA_stream_opt->MSO_TCP_CREATE_LINK_MODE */
+#define TCP_CTEAT_LINK_BYDATA 0x02 /* for MESA_stream_opt->MSO_TCP_CREATE_LINK_MODE */
+
+ /*
+ option of stream,
+
+ MSO_IGNORE_RST_FIN: will not be terminated by RST, FIN packet, only if timeout or in LRU tail, it will be eliminated.
+ */
+ enum MESA_stream_opt
+ {
+ __MSO_PAD = 0, /* placeholder */
+ MSO_MAX_UNORDER = 1, /* opt_val type must be struct max_unorder_opt */
+ MSO_NEED_ACK, /* opt_val type must be unsigned char, value only be [0,1] */
+ MSO_TAKEOVER, /* opt_val type must be int, value only be [0,1] */
+ MSO_TIMEOUT, /* opt_val type must be unsigned short */
+ MSO_IGNORE_RST_FIN, /* opt_val type must be unsigned char, value only be [0,1] */
+ MSO_TCP_CREATE_LINK_MODE, /* opt_val must be unsigned char, refer to TCP_CTEAT_LINK_xxx */
+ MSO_TCP_ISN_C2S, /* Host-order, opt_val type must be unsigned int */
+ MSO_TCP_ISN_S2C, /* Host-order, opt_val type must be unsigned int */
+ MSO_TCP_SYN_OPT, /* opt_val must be struct tcp_option **, opt_val_len [OUT} is struct tcp_option number, valid only if SYN packet is captured */
+ MSO_TCP_SYNACK_OPT, /* opt_val must be struct tcp_option **, opt_val_len [OUT} is struct tcp_option number, valid only if SYN/ACK packet is captured */
+ MSO_STREAM_TUNNEL_TYPE, /* opt_val must be unsigned short, refer to enum stream_carry_tunnel_t */
+ MSO_STREAM_CLOSE_REASON, /* opt_val type must be unsigned char, refer to stream_close_reason_t */
+ MSO_STREAM_VXLAN_INFO, /* opt_val type must be struct vxlan_info, only support for MAC-in-MAC encapsulation in mirror mode */
+ MSO_TCPALL_VALID_AFTER_KILL, /* opt_val type must be unsigned char, value only be [0,1]; Warning, this option is obsolete, use MESA_rst_tcp() instead */
+ MSO_GLOBAL_STREAM_ID, /* opt_val type must be unsigned long long, is value-result argument, IN: device_id, value range[0, 4095]; OUT:global stream id */
+ MSO_DROP_STREAM, /* opt_val type must be int, value only be [0,1]; similar to DROPPKT, but effective scope is all subsequent packets of this stream. */
+ MSO_TCP_RST_REMEDY, /* opt_val type must be int, value only be [0,1]; if not set this, default is disable. */
+ MSO_TOTAL_INBOUND_PKT, /* inbound packet number of this stream, opt_val type must be unsigned long long */
+ MSO_TOTAL_INBOUND_BYTE, /* inbound packet byte of this stream, opt_val type must be unsigned long long */
+ MSO_TOTAL_OUTBOUND_PKT, /* outbound packet pkt of this stream, opt_val type must be unsigned long long */
+ MSO_TOTAL_OUTBOUND_BYTE, /* outbound packet byte of this stream, opt_val type must be unsigned long long */
+ MSO_STREAM_CREATE_TIMESTAMP_MS, /* first pkt arrive timestamp of this stream, opt_val type must be unsigned long long */
+ MSO_TOTAL_INBOUND_BYTE_RAW, /* inbound packet byte of this stream, raw packet len, include ip hdr, ethernet hdr... opt_val type must be unsigned long long */
+ MSO_TOTAL_OUTBOUND_BYTE_RAW, /* outbound packet byte of this stream, raw packet len, include ip hdr, ethernet hdr... opt_val type must be unsigned long long */
+ MSO_STREAM_UP_LAYER_TUNNEL_TYPE, /* opt_val must be unsigned short, refer to enum stream_carry_tunnel_t */
+ MSO_STREAM_PLUG_PME, /* opt_val type must be struct mso_plug_pme, this is a value-result argument, the caller should set plug_name and plug_entry_type, only support: TCP, TCP_ALL, UDP */
+ MSO_DROP_CURRENT_PKT, /* opt_val type must be int, value only be [0,1], notice the difference between MSO_DROP_CURRENT_PKT and MSO_DROP_STREAM, MSO_DROP_CURRENT_PKT only discard current packet, but MSO_DROP_STREAM discard all subsequent packets of stream */
+ MSO_HAVE_DUP_PKT, /* opt_val type must be int, value only be [0, 1, -2], if the current stream found duplicate packets ? 0:no; 1:yes; -2: not sure */
+ MSO_STREAM_LASTUPDATE_TIMESTAMP_MS, /* latest pkt arrive timestamp of this stream, opt_val type must be unsigned long long */
+ MSO_STREAM_TIMED,
+ MSO_STREAM_APPLEND_SEGMENT_ID_LIST,
+ MSO_STREAM_PREPLEND_SEGMENT_ID_LIST,
+ MSO_STREAM_SET_DATAMETA_TRACE_ID,
+ MSO_STREAM_C2S_RAWPKT_HDR,
+ MSO_STREAM_S2C_RAWPKT_HDR,
+ MSO_STREAM_C2S_SYN_NUM,
+ MSO_STREAM_S2C_SYN_NUM,
+ MSO_STREAM_INBOND_LINK_ID,
+ MSO_STREAM_OUTBOND_LINK_ID,
+ MSO_STREAM_C2S_ROUTE_DIRECTION,
+ MSO_STREAM_INBOND_ROUTE_CTX,
+ MSO_STREAM_OUTBOND_ROUTE_CTX,
+ MSO_STREAM_C2S_LINK_ID,
+ MSO_STREAM_S2C_LINK_ID,
+ MSO_STREAM_C2S_ROUTE_CTX,
+ MSO_STREAM_S2C_ROUTE_CTX,
+ MSO_IP_TTL_C2S, /* opt_val type must be unsigned char, IPv4 is TTL, IPv6 is Hop Limit */
+ MSO_IP_TTL_S2C, /* opt_val type must be unsigned char, IPv4 is TTL, IPv6 is Hop Limit */
+ MSO_TCP_RTT_CSC, /* opt_val type must be unsigned short, the full RTT is client->tsg->server->tsg->client, this is |tsg->server->tsg| */
+ MSO_TCP_RTT_SCS, /* opt_val type must be unsigned short, the full RTT is server->tsg->client->tsg->server, this is |tsg->client->tsg| */
+ MSO_STREAM_C2S_SEGMENT_ID_LIST,
+ MSO_STREAM_S2C_SEGMENT_ID_LIST,
+ MSO_STREAM_INBOND_SEGMENT_ID_LIST,
+ MSO_STREAM_OUTBOND_SEGMENT_ID_LIST,
+ MSO_STREAM_UUID, /* opt_val is uuid_t (unsigned char [16]) */
+ __MSO_MAX,
+ };
+
+ /* for MSO_STREAM_CLOSE_REASON,
+ don't confuse, these values is not consecutive indeed, because some value(1,2) is obsoleted!
+ */
+ enum stream_close_reason_t
+ {
+ STREAM_CLOSE_REASON_SYN_REUSE = 0, /* for TCP tuple4 reuse */
+ STREAM_CLOSE_REASON_NORMAL = 3, /* for TCP FIN, FIN/ACK */
+ STREAM_CLOSE_REASON_RESET = 4, /* for TCP RESET */
+ STREAM_CLOSE_REASON_TIMEOUT = 5, /* timeout */
+ STREAM_CLOSE_REASON_LRUOUT = 6, /* stream table full, kick out */
+ STREAM_CLOSE_REASON_DEPRIVE = 7, /* deprive by some plug who return KILL_FOLLOW or KILL_OTHER */
+ STREAM_CLOSE_REASON_DUMPFILE = 8, /* only for pcap dumpfile mode */
+ };
+
+ enum sapp_platform_opt
+ {
+ SPO_TOTAL_RCV_PKT, /* total recv packet number, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_BYTE, /* total recv packet byte, opt_val type must be unsigned long long */
+ SPO_REALTIME_RCV_PKT, /* realtime recv packet number, opt_val type must be unsigned long long */
+ SPO_REALTIME_RCV_BYTE, /* realtime recv packet byte, opt_val type must be unsigned long long */
+ SPO_THREAD_COUNT, /* total thread count, opt_val type must be int */
+ SPO_CURTIME_TIMET, /* current time, opt_val type must be time_t */
+ SPO_CURTIME_STRING, /* current time, opt_val type must be char[], opt_val_len must more than strlen("1970-01-01 01:01:01") */
+ SPO_START_TIME, /* platform start time, opt_val type must be time_t */
+ SPO_RUN_TIME, /* platform running time, opt_val type must be time_t */
+ SPO_RAND_NUMBER, /* get a rand number, opt_val type must be long long */
+ SPO_FIELD_STAT_HANDLE, /* field stat output handle, opt_val type must be void * */
+ SPO_INDEPENDENT_THREAD_ID, /* plug independent thread which is created by pthread_create(), opt_val type must be int */
+ SPO_DEPLOYMENT_MODE_STR, /* opt_val type is char[], optional value is:["mirror", "inline", "transparent"] */
+ SPO_TCP_STREAM_NEW, /* total created tcp streams from start, opt_val type must be unsigned long long */
+ SPO_TCP_STREAM_CLOSE, /* total closed tcp streams from start, opt_val type must be unsigned long long */
+ SPO_TCP_STREAM_ESTAB, /* realtime established tcp streams, opt_val type must be unsigned long long */
+ SPO_TOTAL_INBOUND_PKT, /* total inbound packet number, opt_val type must be unsigned long long */
+ SPO_TOTAL_INBOUND_BYTE, /* total inbound packet bytes, opt_val type must be unsigned long long */
+ SPO_TOTAL_OUTBOUND_PKT, /* total outbound packet number, opt_val type must be unsigned long long */
+ SPO_TOTAL_OUTBOUND_BYTE, /* total outbound packet bytes, opt_val type must be unsigned long long */
+ SPO_UDP_STREAM_NEW, /* total created udp streams from start, opt_val type must be unsigned long long */
+ SPO_UDP_STREAM_CLOSE, /* total closed udp streams from start, opt_val type must be unsigned long long */
+ SPO_UDP_STREAM_CONCURRENT, /* realtime Concurrent udp streams, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_INBOUND_IPV4_PKT, /* total recv ipv4 packet number, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_INBOUND_IPV4_BYTE, /* total recv ipv4 packet number, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_OUTBOUND_IPV4_PKT, /* total recv ipv4 packet bytes, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_OUTBOUND_IPV4_BYTE, /* total recv ipv4 packet bytes, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_INBOUND_IPV6_PKT, /* total recv ipv6 packet number, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_INBOUND_IPV6_BYTE, /* total recv ipv6 packet number, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_OUTBOUND_IPV6_PKT, /* total recv ipv6 packet bytes, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_OUTBOUND_IPV6_BYTE, /* total recv ipv6 packet bytes, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_INBOUND_TCP_PKT, /* total recv tcp packet number, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_INBOUND_TCP_BYTE, /* total recv tcp packet number, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_OUTBOUND_TCP_PKT, /* total recv tcp packet bytes, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_OUTBOUND_TCP_BYTE, /* total recv tcp packet bytes, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_INBOUND_UDP_PKT, /* total recv udp packet number, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_INBOUND_UDP_BYTE, /* total recv udp packet number, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_OUTBOUND_UDP_PKT, /* total recv udp packet bytes, opt_val type must be unsigned long long */
+ SPO_TOTAL_RCV_OUTBOUND_UDP_BYTE, /* total recv udp packet bytes, opt_val type must be unsigned long long */
+ SPO_CURTIME_TIMET_MS, /* current time in millisecond, opt_val type must be long long */
+ SPO_CURRENT_STATE, /* running stage of sapp, opt_val type is enum sapp_state_t */
+ SPO_CONFIG_ROOT_DIR, /* config file root directory, opt_val type must be char[], opt_val_len is value-result argument */
+ SPO_DATA_ROOT_DIR, /* data or state file root directory, opt_val type must be char[], opt_val_len is value-result argument */
+ SPO_DEPLOYMENT_MODE, /* Similar to SPO_DEPLOYMENT_MODE_STR, opt_val type is sapp_deploment_mode_t */
+ SPO_TCP_STREAM_C2S, /* total number of TCP c2s flows processed since start of run, opt_val type must be unsigned long long */
+ SPO_TCP_STREAM_S2C, /* total number of TCP s2c flows processed since start of run, opt_val type must be unsigned long long */
+ SPO_TCP_STREAM_DOUBLE, /* total number of TCP bidirectional flows processed since start of run, opt_val type must be unsigned long long */
+ SPO_UDP_STREAM_C2S, /* total number of TCP c2s flows processed since start of run, opt_val type must be unsigned long long */
+ SPO_UDP_STREAM_S2C, /* total number of TCP s2c flows processed since start of run, opt_val type must be unsigned long long */
+ SPO_UDP_STREAM_DOUBLE, /* total number of TCP bidirectional flows processed since start of run, opt_val type must be unsigned long long */
+ };
+
+ /*
+ option of device,
+ */
+ enum sapp_device_opt
+ {
+ __SDO_PAD = 0, /* placeholder */
+ SDO_MAC_ADDR, /* device mac addr, opt_val type must be at least char[6] */
+ SDO_IPV4_ADDR, /* device ipv4 addr in network order, opt_val type must be int */
+ SDO_MTU, /* device MTU, opt_val type must be int */
+ __SDO_MAX,
+ };
+
+ /* for MSO_MAX_UNORDER */
+ struct max_unorder_opt
+ {
+ unsigned short stream_dir; /* refer to stream_base.h, DIR_C2S, DIR_S2C, DIR_DOUBLE */
+ unsigned short max_unorder_val;
+ };
+
+ enum stream_timer_return_value
+ {
+ KEEP = 0,
+ DROP = 1,
+ };
+
+#define MAX_TCP_OPT_LEN (38) /* TCP max hdr length 60Bytes, set max opt length 38 Bytes */
+#define MAX_TCP_OPT_NUM (20)
+
+ enum tcp_option_value
+ {
+ TCP_OPT_EOL = 0,
+ TCP_OPT_NOP = 1,
+ TCP_OPT_MSS = 2,
+ TCP_OPT_WIN_SCALE = 3,
+ TCP_OPT_SACK = 4,
+ TCP_OPT_SACK_EDGE = 5,
+ TCP_OPT_TIME_STAMP = 8, /* refer to struct tcp_option_ts */
+ TCP_OPT_MD5 = 19,
+ TCP_OPT_MULTI_PATH_TCP = 0x1E,
+ TCP_OPT_RIVER_PROBE = 0x4c,
+ };
+
+ struct tcp_option_ts
+ {
+ unsigned int ts_self;
+ unsigned int ts_echo_reply;
+ };
+
+ struct tcp_option
+ {
+ unsigned char type;
+ unsigned char len; /* pure payload len, not contain type and this len field */
+ union
+ {
+ unsigned char char_value;
+ unsigned short short_value;
+ unsigned int int_value;
+ unsigned long long long_value;
+ char *variable_value;
+ struct tcp_option_ts opt_ts_val;
+ };
+ } __attribute__((packed, aligned(1)));
+
+ struct tcp_option_ext
+ {
+ unsigned char type;
+ unsigned char len;
+ union
+ {
+ unsigned char char_value;
+ unsigned short short_value;
+ unsigned int int_value;
+ unsigned long long long_value;
+ char variable_value[MAX_TCP_OPT_LEN];
+ struct tcp_option_ts opt_ts_val;
+ };
+ } __attribute__((packed, aligned(1)));
+
+ struct vxlan_info
+ {
+ unsigned char encap_type;
+ unsigned char entrance_id;
+ unsigned char dev_id;
+ unsigned char link_id;
+ unsigned char link_dir;
+ unsigned char inner_smac[18]; /*string, "11:22:33:44:55:66" */
+ unsigned char inner_dmac[18]; /* string, "11:22:33:44:55:66" */
+ unsigned char inner_smac_hex[6]; /* hex */
+ unsigned char inner_dmac_hex[6]; /* hex */
+ };
+
+ enum sapp_state_t
+ {
+ SAPP_STATE_JUST_START, /* main() called by shell command */
+ SAPP_STATE_CONFIG_PARSE,
+ SAPP_STATE_PLATFORM_INITING,
+ SAPP_STATE_PLATFORM_INITED, /* 3 */
+ SAPP_STATE_PLUG_INITING,
+ SAPP_STATE_PLUG_INITED, /* 5 */
+ SAPP_STATE_PKT_IO_INITING,
+ SAPP_STATE_PKT_IO_INITED,
+ SAPP_STATE_PROCESSING, /* 8 */
+ SAPP_STATE_READY_TO_EXIT, /* 9, pcap dumpfile mode, or recv custom signal */
+ SAPP_STATE_EXIT,
+ };
+
+ struct mso_plug_pme
+ {
+ const char *plug_name; /* argument: IN, comes from plug.inf-->[PLUGINFO]-->PLUGNAME */
+ const char *plug_entry_type; /* argument: IN, only support: TCP, TCP_ALL, UDP. */
+ void *plug_pme; /* argument: OUT, plug private memory address of current stream */
+ };
+
+ enum sapp_deploment_mode_t
+ {
+ DEPLOYMENT_MODE_MIRROR = 1,
+ DEPLOYMENT_MODE_TRANSPARENT = 2,
+ DEPLOYMENT_MODE_INLINE = 3,
+ };
#ifndef MAX_SID_NUM
#define MAX_SID_NUM 8
#endif
-struct segment_id_list
-{
- unsigned short sid_list[MAX_SID_NUM];
- unsigned int sz_sidlist;
-};
-
-int append_sid_to_rawpkt(const void *rawpkt, struct segment_id_list *sid_list);
-int prepend_sid_to_rawpkt(const void *rawpkt, struct segment_id_list *sid_list);
-
-struct streaminfo;
-/*
- plug call MESA_set_stream_opt() to set feature of specified stream.
- opt: option type, refer to enum MESA_stream_opt;
- opt_val: option value, depend on opt type;
- opt_val_len: opt_val size;
-
- return value:
- 0 :OK;
- <0:error;
-*/
-int MESA_set_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt opt, void *opt_val, int opt_val_len);
-
-
-/*
- plug call MESA_get_stream_opt() to get feature of specified stream.
- opt: option type, refer to enum MESA_stream_opt;
- opt_val: option value, depend on opt type;
- opt_val_len: value-result argment, IN:opt_val buf size, OUT:opt_val actual size;
-
- return value:
- 0 :OK;
- <0:error;
-*/
-int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt opt, void *opt_val, int *opt_val_len);
-
-
-struct tcphdr;
-/*
- Get options from tcphdr, and store them in raw_result.
- return value:
- = 0: no option;
- > 0: opt number;
- < 0: error.
-*/
-int MESA_get_tcp_pkt_opts(const struct tcphdr *tcphdr, struct tcp_option *raw_result, int res_num);
-
-
-/*
- Get options from tcphdr, and store them in raw_result.
- return value:
- = 0: no option;
- > 0: opt number;
- < 0: error.
-*/
-int MESA_get_tcp_pkt_opts_ext(const struct tcphdr *tcphdr, struct tcp_option_ext *raw_result, int res_num);
-
-/*
- plug call sapp_get_platform_opt() to get feature of platform.
- opt: option type, refer to enum sapp_platform_opt;
- opt_val: option value, depend on opt type;
- opt_val_len: value-result argment, IN:opt_val buf size, OUT:opt_val actual size;
-
- return value:
- 0 :OK;
- <0:error;
-*/
-int sapp_get_platform_opt(enum sapp_platform_opt opt, void *opt_val, int *opt_val_len);
-
-
-/*
- Get some options of hardware .
- opt: option type, refer to enum sapp_device_opt;
- opt_val: option value, depend on opt type;
- opt_val_len: value-result argment, IN:opt_val buf size, OUT:opt_val actual size;
-
- return value:
- 0 :OK;
- <0:error;
-*/
-int sapp_get_device_opt(const char *device, enum sapp_device_opt opt_type, void *opt_val, int *opt_val_len);
-
-/***************************************************************************************
- NOTE:
- convernt by etc/sapp.toml->inbound_route_dir.
-
- args:
- 'E' or 'e': Internal to External.
- 'I' or 'i': External to Internal.
-
- return value:
- 0 or 1: success.
- -1 : error.
-****************************************************************************************/
-int MESA_dir_human_to_link(int human_dir);
-
-/*
- args:
- 0 or 1, stream->routedir;
-
- return value:
- 'E' or 'e': Internal to External.
- 'I' or 'i': External to Internal.
- 'x': error;
-*/
-int MESA_dir_link_to_human(int link_route_dir);
-
-
-
-/****************************************************************************************
- for compat old version, keep these functions, but we suggest you use new API MESA_set_stream_opt().
-*****************************************************************************************/
-int tcp_set_single_stream_max_unorder(const struct streaminfo *stream, unsigned char dir, unsigned short unorder_num);
-int tcp_set_single_stream_needack(const struct streaminfo *pstream);
-int tcp_set_single_stream_takeoverflag(const struct streaminfo *pstream,int flag);
-int stream_set_single_stream_timeout(const struct streaminfo *pstream,unsigned short timeout);
-int get_thread_count(void);
-/****************************************************************************************
-****************************************************************************************
-****************************************************************************************/
+ struct segment_id_list
+ {
+ unsigned short sid_list[MAX_SID_NUM];
+ unsigned int sz_sidlist;
+ };
+
+ int append_sid_to_rawpkt(const void *rawpkt, struct segment_id_list *sid_list);
+ int prepend_sid_to_rawpkt(const void *rawpkt, struct segment_id_list *sid_list);
+
+ struct streaminfo;
+ /*
+ plug call MESA_set_stream_opt() to set feature of specified stream.
+ opt: option type, refer to enum MESA_stream_opt;
+ opt_val: option value, depend on opt type;
+ opt_val_len: opt_val size;
+
+ return value:
+ 0 :OK;
+ <0:error;
+ */
+ int MESA_set_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt opt, void *opt_val, int opt_val_len);
+
+ /*
+ plug call MESA_get_stream_opt() to get feature of specified stream.
+ opt: option type, refer to enum MESA_stream_opt;
+ opt_val: option value, depend on opt type;
+ opt_val_len: value-result argment, IN:opt_val buf size, OUT:opt_val actual size;
+
+ return value:
+ 0 :OK;
+ <0:error;
+ */
+ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt opt, void *opt_val, int *opt_val_len);
+
+ struct tcphdr;
+ /*
+ Get options from tcphdr, and store them in raw_result.
+ return value:
+ = 0: no option;
+ > 0: opt number;
+ < 0: error.
+ */
+ int MESA_get_tcp_pkt_opts(const struct tcphdr *tcphdr, struct tcp_option *raw_result, int res_num);
+
+ /*
+ Get options from tcphdr, and store them in raw_result.
+ return value:
+ = 0: no option;
+ > 0: opt number;
+ < 0: error.
+ */
+ int MESA_get_tcp_pkt_opts_ext(const struct tcphdr *tcphdr, struct tcp_option_ext *raw_result, int res_num);
+
+ /*
+ plug call sapp_get_platform_opt() to get feature of platform.
+ opt: option type, refer to enum sapp_platform_opt;
+ opt_val: option value, depend on opt type;
+ opt_val_len: value-result argment, IN:opt_val buf size, OUT:opt_val actual size;
+
+ return value:
+ 0 :OK;
+ <0:error;
+ */
+ int sapp_get_platform_opt(enum sapp_platform_opt opt, void *opt_val, int *opt_val_len);
+
+ /*
+ Get some options of hardware .
+ opt: option type, refer to enum sapp_device_opt;
+ opt_val: option value, depend on opt type;
+ opt_val_len: value-result argment, IN:opt_val buf size, OUT:opt_val actual size;
+
+ return value:
+ 0 :OK;
+ <0:error;
+ */
+ int sapp_get_device_opt(const char *device, enum sapp_device_opt opt_type, void *opt_val, int *opt_val_len);
+
+ /***************************************************************************************
+ NOTE:
+ convernt by etc/sapp.toml->inbound_route_dir.
+
+ args:
+ 'E' or 'e': Internal to External.
+ 'I' or 'i': External to Internal.
+
+ return value:
+ 0 or 1: success.
+ -1 : error.
+ ****************************************************************************************/
+ int MESA_dir_human_to_link(int human_dir);
+
+ /*
+ args:
+ 0 or 1, stream->routedir;
+
+ return value:
+ 'E' or 'e': Internal to External.
+ 'I' or 'i': External to Internal.
+ 'x': error;
+ */
+ int MESA_dir_link_to_human(int link_route_dir);
+
+ /****************************************************************************************
+ for compat old version, keep these functions, but we suggest you use new API MESA_set_stream_opt().
+ *****************************************************************************************/
+ int tcp_set_single_stream_max_unorder(const struct streaminfo *stream, unsigned char dir, unsigned short unorder_num);
+ int tcp_set_single_stream_needack(const struct streaminfo *pstream);
+ int tcp_set_single_stream_takeoverflag(const struct streaminfo *pstream, int flag);
+ int stream_set_single_stream_timeout(const struct streaminfo *pstream, unsigned short timeout);
+ int get_thread_count(void);
+ /****************************************************************************************
+ ****************************************************************************************
+ ****************************************************************************************/
#ifdef __cplusplus
}
#endif
#endif
-
diff --git a/module_test/src/gtest_main.cpp b/module_test/src/gtest_main.cpp index 91ef42f..6c09d49 100644 --- a/module_test/src/gtest_main.cpp +++ b/module_test/src/gtest_main.cpp @@ -25,7 +25,7 @@ const char *user_define_args; const char *for_test_sapp_version = "4.2.68_c9193fe"; -static int g_libsapp_devel_res = GTEST_SAPP_ERR; /* 使用lisapp_devel.so在同一个进程内运行的测试结�???*/ +static int g_libsapp_devel_res = GTEST_SAPP_ERR; /* 使用lisapp_devel.so在同一个进程内运行的测试结�????*/ int gtest_set_libsapp_devel_result(int res_value) { g_libsapp_devel_res = res_value; @@ -171,7 +171,7 @@ void call_libsapp_devel_online_mode(void) while(sapp_get_current_state() != SAPP_STATE_PROCESSING){ usleep(100); } - sleep(3); /* TODO: 此处不用超时, 而是靠一个标志位或特定状�???*/ + sleep(3); /* TODO: 此处不用超时, 而是靠一个标志位或特定状�????*/ libsapp_destroy_env(); } @@ -991,6 +991,13 @@ TEST(control, get_tcp_rtt_s2c) // EXPECT_EXIT(control_get_tcp_rtt_run(), testing::ExitedWithCode(0), "test succ"); } +TEST(control, get_stream_uuid) +{ + control_get_stream_uuid_run(); + ASSERT_EQ(GTEST_SAPP_SUCC, gtest_get_libsapp_devel_result()); + // EXPECT_EXIT(control_get_tcp_rtt_run(), testing::ExitedWithCode(0), "test succ"); +} + /************************ project_requirement.h API test ***********************/ #define project_simple 1 // for SI symbol view TEST(project, simple) @@ -1336,7 +1343,7 @@ TEST(timer, DISABLED_simple) /********************* inject rst packet Test ***********************/ #if SAPP_V4 //rst_tcp only support in sapp-v4.0 -#if 0 /* 改成用sapp_benchmark框架测试, 不需要写代码、不用重新编�???*/ +#if 0 /* 改成用sapp_benchmark框架测试, 不需要写代码、不用重新编�????*/ #define inject_rst_packet_test_v4 1 // for SI symbol view TEST(inject, rst_pkt_v4) { @@ -1347,7 +1354,7 @@ TEST(inject, rst_pkt_v4) /********************* inject rst packet Test ***********************/ #define inject_rst_packet_test_v6 1 // for SI symbol view -#if 0 /* 改成用sapp_benchmark框架测试, 不需要写代码、不用重新编�???*/ +#if 0 /* 改成用sapp_benchmark框架测试, 不需要写代码、不用重新编�????*/ TEST(inject, rst_pkt_v6) { MESA_rst_tcp_test_v6_run(); @@ -2054,7 +2061,7 @@ TEST(proxy, simple) #define _proxy_kill_tcp 1 /* TODO: - 使用libsapp_devel实测, 两个用例不能顺序执行, 疑似与解析层dlopen有关�??? 暂未定位原因, 待解�???!!! + 使用libsapp_devel实测, 两个用例不能顺序执行, 疑似与解析层dlopen有关�???? 暂未定位原因, 待解�????!!! */ #if 0 TEST(proxy, kill_tcp) @@ -2176,7 +2183,7 @@ TEST(fake_marsio, vlan_flip_and_symmetric_mpls1vs2) #define _fake_marsio_vlan_mac_flip_inject_no_asymmetric 1 TEST(fake_marsio, vlan_mac_flip_inject_no_asymmetric) { - /* 别着�??? 不是BUG! + /* 别着�???? 不是BUG! 这个测试用例就是应该错的 !!! */ EXPECT_EXIT(fake_marsio_vlan_mac_flipping_inject_run(0), testing::ExitedWithCode(1), "index:4, mac addr error"); diff --git a/module_test/src/gtest_sapp_fun.h b/module_test/src/gtest_sapp_fun.h index 96f76d1..3298c1e 100644 --- a/module_test/src/gtest_sapp_fun.h +++ b/module_test/src/gtest_sapp_fun.h @@ -16,8 +16,8 @@ /* 说明: - 为了方便测试sapp的某些功�?不得已引用了一些private级别的头文件, - 但是如果sapp的头文件更新�? 但此模块没同步更�? 导致结构体不一�? 可能会测试不通过. + 为了方便测试sapp的某些功�??不得已引用了一些private级别的头文件, + 但是如果sapp的头文件更新�?? 但此模块没同步更�?? 导致结构体不一�?? 可能会测试不通过. */ #include "sapp_limits.h" @@ -51,8 +51,8 @@ #define GTEST_INLINE_TO_SAPP_SUCC (0x07654321) /* inline模式下TAP模拟外部设备检测正确返回�?*/ #define GTEST_TRANSPARENT_TO_SAPP_SUCC (0x00ABCDEF) /* 双臂模式下TAP模拟外部设备检测正确返回�?*/ #define GTEST_FAKE_MARSIO_SUCC (0x0FEFEFE0) /* fake marsio模式检测正确返回�?*/ -#define GTEST_SAPP_ERR_SKIP (0x534B4950U) /* 因sapp的内部结构体变化, 无法测试, 跳过此用例的返回�? 即字符SKIP的十六进�?*/ -#define GTEST_RESULT_NONE (0x4E4F4E45) /* "NONE"�?6进制, 不发送或者表示无任何意义的返回�?*/ +#define GTEST_SAPP_ERR_SKIP (0x534B4950U) /* 因sapp的内部结构体变化, 无法测试, 跳过此用例的返回�?? 即字符SKIP的十六进�??*/ +#define GTEST_RESULT_NONE (0x4E4F4E45) /* "NONE"�??6进制, 不发送或者表示无任何意义的返回�?*/ #define BENCHMARK_PCAP_ROOT_DIR "../benchmark_pcap" @@ -68,7 +68,7 @@ #define SAPP_GTEST_LOG(level, module, fmt, args...) do{MESA_handle_runtime_log(g_sapp_test_log_handle, level, module, fmt, ##args);}while(0) -/* 用于sapp插件上下文空�? 有可能是被fork之后调用sapp, 跟gtest_main函数不在同一个进程里 */ +/* 用于sapp插件上下文空�?? 有可能是被fork之后调用sapp, 跟gtest_main函数不在同一个进程里 */ #define SAPP_PLUG_LOG(level, module, fmt, args...) do{MESA_handle_runtime_log(g_sapp_plug_log_handle, level, module, fmt, ##args);}while(0) @@ -148,7 +148,7 @@ enum gtest_inject_type{ GINJECT_UDP_PAYLOAD = GINJECT_TYPE_UDP|0x01, }; -/* 用于指定哪些pcap�? 对应哪些检测函�?*/ +/* 用于指定哪些pcap�?? 对应哪些检测函�??*/ typedef struct { const char *pcap_file_md5; unsigned int default_check_result; @@ -159,8 +159,8 @@ typedef struct { typedef struct { const char *pcap_file_md5; const char *keepalive_ip; /* inline 回流 保活ip */ - int inject_reverse; /* 注入包是否反�?*/ - int inject_pkt_trigger_threshold; /* inject超过几个包发送成功结�?*/ + int inject_reverse; /* 注入包是否反�??*/ + int inject_pkt_trigger_threshold; /* inject超过几个包发送成功结�??*/ unsigned int default_check_result; void (*pcap_callback)(u_char *user, const struct pcap_pkthdr *hdr, const u_char *data); const char *description; @@ -224,7 +224,7 @@ void gtest_exec_printf(const char *fmt, ...); void gtest_plug_printf(const char *fmt, ...); -extern "C" void sapp_printf(const char *fmt, ...); /* 在插件的上下文调�?*/ +extern "C" void sapp_printf(const char *fmt, ...); /* 在插件的上下文调�??*/ extern "C" int gtest_sapp_slave_init(void); /*********************************** tcp **************************************/ void tcp_simple_run(void); @@ -379,6 +379,7 @@ void control_get_ip_ttl_run(void); void control_get_tcp_rtt_run(void); void control_get_tcp_rtt_c2s_run(void); void control_get_tcp_rtt_s2c_run(void); +void control_get_stream_uuid_run(void); /****************************** tunnel **************************/ void teredo_unstandard_port_run(void); void teredo_with_auth_hdr_run(void); diff --git a/module_test/src/gtest_sapp_support.cpp b/module_test/src/gtest_sapp_support.cpp index 263ba39..b252901 100644 --- a/module_test/src/gtest_sapp_support.cpp +++ b/module_test/src/gtest_sapp_support.cpp @@ -21,7 +21,7 @@ void control_max_unorder_run(void) { set_default_config(); #if SAPP_V3 - update_config_file("conf/main.conf", "MaxUnorderNum", "3"); /* ȫ�����������С��ʵ������İ����, �ᵼ����Ϊ�Ƕ��� */ + update_config_file("conf/main.conf", "MaxUnorderNum", "3"); /* ȫ�����������С��ʵ������İ����?, �ᵼ����Ϊ�Ƕ��� */ #elif SAPP_V4 update_config_file("etc/sapp.toml", "reorder_pkt_max", "3"); #else @@ -201,7 +201,7 @@ void control_tunnel_type_l2tp_run(void) { set_default_config(); - /* l2tpʶ��Ŀǰ��Ҫ����l2tp_protocol��� */ + /* l2tpʶ��Ŀǰ��Ҫ����l2tp_protocol���? */ insert_into_conflist_inf("protocol", "./plug/protocol/l2tp_protocol_plug/l2tp_protocol_plug.inf"); update_plugin_inf("TCP", "ctrl_tunnel_l2tp_entry"); @@ -245,7 +245,7 @@ void control_tunnel_type_gtp_run(void) call_libsapp_devel_with_args(2, sapp_start_args); } -/* ����sapp_get_platform_opt()�ӿ���ع��� */ +/* ����sapp_get_platform_opt()�ӿ���ع���? */ void control_stream_and_traffic_run(void) { set_default_config(); @@ -302,10 +302,10 @@ void project_nodify_run(void) /* ����gtest.inf */ update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "project_test_init", NULL, "TCP", "project_customer_entry"); - /* project_producer_notify_entry ע�ᵽTCP_ALL, ��֤Ҫ����TCP�������, �Ȳ���projectֵ */ + /* project_producer_notify_entry ע�ᵽTCP_ALL, ��֤Ҫ����TCP�������?, �Ȳ���projectֵ */ append_plugin_inf("TCP_ALL", "project_producer_notify_entry"); - /* ����sapp_appstate���������IJ��Ŀ¼, ��������project nofity���� */ + /* ����sapp_appstate���������IJ��Ŀ�?, ��������project nofity���� */ update_plugin_inf_with_options("./plug/business/gtest_sapp_appstate_1", "notify1", "project_nofity_custom1_init", NULL, "TCP", "project_customer_entry1"); update_plugin_inf_with_options("./plug/business/gtest_sapp_appstate_2", "notify2", "project_nofity_custom2_init", NULL, "TCP", "project_customer_entry2"); @@ -351,7 +351,7 @@ void timer_simple_run(void) /* ����һ��pcap��, ʹ�����dz���, ʹ��--dumpfile-speed=timestamp����,��֤ƽ̨��ʱ�䲻�˳�! - �����pcap_onlineģʽ����lo��,�dz�����û������,���²�����ᱻ����. + �����pcap_onlineģʽ����lo��,�dz�����û������,���²�����ᱻ����?. */ set_pcap_dumpfile("for_gtest_only/timer/timer_tcp_test.pcap"); ASSERT_EQ(file_md5_checksum("dumpfile", "7bfc59d66bb44f76603cd6cedfd19091"),0); @@ -421,7 +421,7 @@ void global_stream_id_tuple4_reuse_run(void) } /* - ������Ԫ�����ú�, ���Ĵ���ʱ���Ƿ����. + ������Ԫ�����ú�, ���Ĵ���ʱ���Ƿ����?. */ void stream_creattime_tuple4_reuse_run(void) { @@ -489,7 +489,7 @@ void control_platform_opt_run(void) { set_default_config(); - /* ����gtest.inf, �˴���Ҫ�Ǹ���test_get_platform_opt_init()����, �����ʵ����ν, ���Ӹ�tcp��� */ + /* ����gtest.inf, �˴���Ҫ�Ǹ���test_get_platform_opt_init()����, �����ʵ�����?, ���Ӹ�tcp���? */ update_plugin_inf_with_options("./plug/business/gtest_sapp", "gtest", "test_get_platform_opt_init", NULL, "TCP", "tcp_simple"); set_pcap_dumpfile("tcp/tcp_simple.pcap"); @@ -519,12 +519,12 @@ void control_stream_create_timestamp_ms_run(void) } -/* ���Ի�ȡ��ǰ���ϲ���ص�����, ��ײ�������ͬ */ +/* ���Ի�ȡ��ǰ���ϲ���ص�����?, ��ײ��������? */ void control_up_layer_tunnel_gtp_run(void) { set_default_config(); - /* gtp_dns.pcap�м����ظ����ݰ�, �ùر��ظ������� */ + /* gtp_dns.pcap�м����ظ����ݰ�, �ùر��ظ�������? */ update_config_file("etc/sapp.toml", "original_ipv4_udp_enabled", "0"); update_config_file("etc/sapp.toml", "inject_all_enabled", "0"); @@ -538,12 +538,12 @@ void control_up_layer_tunnel_gtp_run(void) } -/* ���Ի�ȡ��ǰ���ϲ���ص�����, ��ײ�������ͬ */ +/* ���Ի�ȡ��ǰ���ϲ���ص�����?, ��ײ��������? */ void control_up_layer_tunnel_l2tp_run(void) { set_default_config(); - /* l2tpʶ��Ŀǰ��Ҫ����l2tp_protocol��� */ + /* l2tpʶ��Ŀǰ��Ҫ����l2tp_protocol���? */ insert_into_conflist_inf("protocol", "./plug/protocol/l2tp_protocol_plug/l2tp_protocol_plug.inf"); update_plugin_inf("UDP", "up_layer_tunnel_l2tp_entry"); @@ -556,7 +556,7 @@ void control_up_layer_tunnel_l2tp_run(void) } -/* ���Ի�ȡ��ǰ���ϲ���ص�����, ��ײ�������ͬ */ +/* ���Ի�ȡ��ǰ���ϲ���ص�����?, ��ײ��������? */ void control_up_layer_tunnel_teredo_run(void) { set_default_config(); @@ -576,14 +576,14 @@ void control_get_plug_pme_run(void) { set_default_config(); - update_plugin_inf("TCP", "void_entry"); /* �˲����Ҫ���ڵ��� gtest_sapp_slave_init, entry����ɶҲ���� */ + update_plugin_inf("TCP", "void_entry"); /* �˲����Ҫ���ڵ���? gtest_sapp_slave_init, entry����ɶҲ���� */ update_plugin_inf_with_options("./plug/business/gtest_get_plug_pme1", "get_plug_pme1", "get_plug_pme_init", NULL, "TCP_ALL", "get_plug_pme_tcpall_entry"); update_plugin_inf_with_options("./plug/business/gtest_get_plug_pme2", "get_plug_pme2", "get_plug_pme_init", NULL, "TCP", "get_plug_pme_tcp_entry"); /* ��Ҫע��: sapp����business�����dlopen + RTLD_LOCAL����ģʽ, ������-l��ϵͳ�Զ����ص�, - ������ͬ�������ں���������Ȼһ��, ���ڴ��ַʵ���Dz�һ����!! + ������ͬ�������ں���������Ȼһ��, ���ڴ��ַʵ���Dz�һ����?!! ������Ҫ���ص�platform��. */ update_plugin_inf_with_options("./plug/platform/gtest_get_plug_pme3", "get_plug_pme3", "get_plug_pme_init", NULL, "UDP", "get_plug_pme_udp_entry1"); @@ -609,12 +609,12 @@ void control_get_plug_pme_run(void) } -/* ���Ա�Ҫ����ij�ʼ��, ���.inf��.so������, init()�������ش��� */ +/* ���Ա�Ҫ����ij�ʼ��?, ���?.inf��.so������, init()�������ش��� */ void control_plug_necessary_run(void) { set_default_config(); - /* Ĭ�Ͻ���dzɹ�, ���Dz�����ʹ����� */ + /* Ĭ�Ͻ���dzɹ�?, ���Dz�����ʹ�����? */ gtest_set_timeout_default_result(GTEST_SAPP_SUCC); update_plugin_inf_with_options("./plug/business/necessary", "plug_necessary", "plug_necessary_init", NULL, "TCP", "plug_necessary_not_call_entry"); @@ -634,12 +634,12 @@ void control_plug_necessary_run(void) call_libsapp_devel_with_args(2, sapp_start_args); } -/* ���Ա�Ҫ����ij�ʼ��,���Dz��.inf������, ��ȡ���.so·��, �����������Ȼ���ִ��� */ +/* ���Ա�Ҫ����ij�ʼ��?,���Dz��?.inf������, ��ȡ���?.so·��, �����������Ȼ���ִ���? */ void control_plug_necessary_run_no_inf(void) { set_default_config(); - /* Ĭ�Ͻ���dzɹ�, ���Dz�����ʹ����� */ + /* Ĭ�Ͻ���dzɹ�?, ���Dz�����ʹ�����? */ gtest_set_timeout_default_result(GTEST_SAPP_SUCC); update_plugin_inf_with_options("./plug/business/necessary", "plug_necessary", "plug_necessary_init", NULL, "TCP", "plug_necessary_not_call_entry"); @@ -659,12 +659,12 @@ void control_plug_necessary_run_no_inf(void) } -/* ���Ա�Ҫ����ij�ʼ��,���.inf����, ����.so������, dlopen����ִ��� */ +/* ���Ա�Ҫ����ij�ʼ��?,���?.inf����, ����.so������, dlopen����ִ���? */ void control_plug_necessary_run_no_sofile(void) { set_default_config(); - /* Ĭ�Ͻ���dzɹ�, ���Dz�����ʹ����� */ + /* Ĭ�Ͻ���dzɹ�?, ���Dz�����ʹ�����? */ gtest_set_timeout_default_result(GTEST_SAPP_SUCC); update_plugin_inf_with_options("./plug/business/necessary", "plug_necessary", "plug_necessary_init", NULL, "TCP", "plug_necessary_not_call_entry"); @@ -685,7 +685,7 @@ void control_plug_necessary_run_no_sofile(void) } -/* ���Բ����ȡ�ظ�����״̬, tcp�� */ +/* ���Բ����ȡ�ظ�����״�?, tcp�� */ void control_plug_dup_pkt_tcp_run(void) { set_default_config(); @@ -706,7 +706,7 @@ void control_plug_dup_pkt_tcp_run(void) } -/* ���Բ����ȡ�ظ�����״̬, udp�� */ +/* ���Բ����ȡ�ظ�����״�?, udp�� */ void control_plug_dup_pkt_udp_run(void) { set_default_config(); @@ -726,7 +726,7 @@ void control_plug_dup_pkt_udp_run(void) } /* - ͨ�������в���-c�������ļ���Ŀ¼, -D�������ļ���Ŀ¼��IJ���. + ͨ�������в���-c�������ļ���Ŀ¼, -D�������ļ���Ŀ¼��IJ���?. */ void control_get_root_dir_run(void) { @@ -755,7 +755,7 @@ void control_get_root_dir_run(void) update_config_file("./etc/sapp.toml", "dumpfile_sleep_time_before_exit", "0"); - /* ��Ϊ�����ļ�·�������'/', ���sed�����ͻ, ��Ҫʹ�ö���ת��, + /* ��Ϊ�����ļ�·�������?'/', ���sed������?, ��Ҫʹ�ö���ת��, ��һ��������������\\, ��ʾ��ʵ��'\', �ڶ���ת�����ʵ�����\x2F, ����sed��˵��ʾ��ʵ��'/' */ @@ -778,7 +778,7 @@ void control_get_root_dir_run(void) call_libsapp_devel_with_args(8, sapp_change_root_dir_args); - /* ִ������ټ��һ������Ŀ¼�Ƿ���sysinfo.log, �Ƿ���־������ݷ���Ԥ�� */ + /* ִ������ټ��һ������Ŀ¼�Ƿ���sysinfo.log, �Ƿ���־������ݷ���Ԥ��? */ ASSERT_EQ(expect_file_has_some_string("/tmp/sapp_change_root_dir_test/data/sysinfo.log", "17.75K"), 0); ASSERT_EQ(expect_file_has_some_string("/tmp/sapp_change_root_dir_test/data/sysinfo.log", "16.82K"), 0); ASSERT_EQ(expect_file_has_some_string("/tmp/sapp_change_root_dir_test/data/sysinfo.log", "13674"), 0); @@ -792,7 +792,7 @@ void stream_bridge_test_run(void) { set_default_config(); - /* ������Ҫ�����������bridge����, ���������²��Ŀ¼ */ + /* ������Ҫ�����������bridge����, ���������²��Ŀ�? */ system("mkdir -p ./plug/business/gtest_sapp_1"); system("mkdir -p ./plug/business/gtest_sapp_2"); system("cp ./plug/business/gtest_sapp/libgtest_sapp.so ./plug/business/gtest_sapp_1/"); @@ -830,7 +830,7 @@ void find_streaminfo_v4_run(void) set_default_config(); - update_config_file("etc/sapp.toml", "worker_threads", "4"); /* ���߳������һЩ, �����ڲ�ͬ�߳���polling���ҹ��� */ + update_config_file("etc/sapp.toml", "worker_threads", "4"); /* ���߳������һ�?, �����ڲ�ͬ�߳���polling���ҹ��� */ update_config_file("etc/sapp.toml", "syn_mandatory", "0"); update_config_file("etc/sapp.toml", "reorder_pkt_max", "100"); update_config_file("etc/sapp.toml", "timeout", "0"); @@ -857,7 +857,7 @@ void find_streaminfo_v6_run(void) set_default_config(); - update_config_file("etc/sapp.toml", "worker_threads", "6"); /* ���߳������һЩ, �����ڲ�ͬ�߳���polling���ҹ��� */ + update_config_file("etc/sapp.toml", "worker_threads", "6"); /* ���߳������һ�?, �����ڲ�ͬ�߳���polling���ҹ��� */ update_config_file("etc/sapp.toml", "syn_mandatory", "0"); update_config_file("etc/sapp.toml", "reorder_pkt_max", "100"); update_config_file("etc/sapp.toml", "timeout", "0"); @@ -907,7 +907,7 @@ void find_streaminfo_diff_tunnel_v4_run(void) /* ���������breakpad��forkһ���½��̣��ռ������ֳ������ϴ����������� - �˹��̻�̳�sapp����������socket�����minidump�ϴ�ʱ��Ƚϳ��� + �˹��̻�̳�sapp����������socket�����minidump�ϴ�ʱ��Ƚϳ���? �ᵼ��sapp������ʱ�ᷢ�ֶ˿ڻ��ڱ�minidumpռ�ã�������ʱ������ ������������֤sapp��socket��ռ�ö˿��Ƿ��ܱ���ʱ�ر�. */ @@ -940,7 +940,7 @@ void control_fork_listen_port_run(void) call_libsapp_devel_with_args(3, sapp_timestamp_argv); - /*************** ִ�е��˴�, ��sapp�����Ѿ��˳�, fork������sapp�ӽ��̿��ܸո�����, ���һ��12345�Ƿ�ռ�� *****************/ + /*************** ִ�е��˴�, ��sapp�����Ѿ��˳�, fork������sapp�ӽ��̿��ܸո�����, ���һ��?12345�Ƿ�ռ�� *****************/ sleep(1); @@ -953,7 +953,7 @@ void control_fork_listen_port_run(void) fgets(result, sizeof(result), result_fp); - if(strlen(result) == 0){ /* netstat�������, ����ȷ�� */ + if(strlen(result) == 0){ /* netstat�������?, ����ȷ�� */ printf("\033[32mfork_listen_port test success!\033[0m\n"); gtest_set_libsapp_devel_result(GTEST_SAPP_SUCC); }else{ @@ -1024,7 +1024,7 @@ void get_deployment_mode_mirror(void) set_default_config(); update_plugin_inf("TCP", "get_deployment_mode_tcp_udp_entry"); - set_pcap_dumpfile("tcp/tcp_simple.pcap"); /* ����Ҹ���, ʲô����, ����Ϊ������, ����ģʽ�İ�Ҫ��һ�� */ + set_pcap_dumpfile("tcp/tcp_simple.pcap"); /* ����Ҹ���?, ʲô����, ����Ϊ������, ����ģʽ�İ�Ҫ��һ�� */ ASSERT_EQ(file_md5_checksum("dumpfile", "df138740a6a22ca9c977052f21f7a470"),0); call_libsapp_devel_with_args(2, sapp_start_args); @@ -1040,7 +1040,7 @@ void get_deployment_mode_transparent(void) update_config_file_by_lastNline("etc/sapp.toml", "packet_io.internal.interface", 2, "name", "lo"); update_config_file_by_lastNline("etc/sapp.toml", "packet_io.external.interface", 1, "name", "lo"); update_config_file_by_lastNline("etc/sapp.toml", "packet_io.external.interface", 2, "name", "lo"); - set_pcap_dumpfile("tcp/tcp_isn_c2s_single.pcap"); /* ����Ҹ���, ʲô����, ����Ϊ������, ����ģʽ�İ�Ҫ��һ�� */ + set_pcap_dumpfile("tcp/tcp_isn_c2s_single.pcap"); /* ����Ҹ���?, ʲô����, ����Ϊ������, ����ģʽ�İ�Ҫ��һ�� */ ASSERT_EQ(file_md5_checksum("dumpfile", "a5d0d96ee6f44f729d79aeac5cc2fee0"),0); call_libsapp_devel_with_args(1, sapp_transparent_start_args); @@ -1061,7 +1061,7 @@ void get_deployment_mode_inline(void) update_config_file("etc/gdev.conf", "sendto_gdev_ip", "10.3.36.1"); update_plugin_inf("POLLING", "get_deployment_mode_tcp_udp_entry"); - set_pcap_dumpfile("for_gtest_only/inline/tcp_flow_stat.pcap"); /* ����Ҹ���, ʲô����, ����Ϊ������, ����ģʽ�İ�Ҫ��һ�� */ + set_pcap_dumpfile("for_gtest_only/inline/tcp_flow_stat.pcap"); /* ����Ҹ���?, ʲô����, ����Ϊ������, ����ģʽ�İ�Ҫ��һ�� */ ASSERT_EQ(file_md5_checksum("dumpfile", "917fd6b8bc70e02812a036adf637479b"),0); call_libsapp_devel_with_args(1, sapp_inline_start_args); @@ -1114,3 +1114,12 @@ void control_get_tcp_rtt_s2c_run(void) call_libsapp_devel_for_dumpfile_topspeed(); } + +void control_get_stream_uuid_run(void) +{ + set_default_config(); + update_plugin_inf("TCP", "ctrl_get_stream_uuid_entry"); + set_pcap_dumpfile("tcp/tcp_simple.pcap"); + ASSERT_EQ(file_md5_checksum("dumpfile", "df138740a6a22ca9c977052f21f7a470"),0); + call_libsapp_devel_with_args(2, sapp_start_args); +} diff --git a/module_test/src/gtest_sapp_support_plug.cpp b/module_test/src/gtest_sapp_support_plug.cpp index 371d969..7e462c5 100644 --- a/module_test/src/gtest_sapp_support_plug.cpp +++ b/module_test/src/gtest_sapp_support_plug.cpp @@ -32,7 +32,7 @@ extern "C" char ctrl_max_unorder_tcp_entry(struct streaminfo *pstream,void **pme { memset(>est_ctrl_tcp_stat, 0, sizeof(gtest_plug_stat_t)); mopt.stream_dir = DIR_DOUBLE; - mopt.max_unorder_val = 5; /* 重置当前流的最大乱序数为5 */ + mopt.max_unorder_val = 5; /* 重置当前流的最大乱序数�?5 */ ret = MESA_set_stream_opt(pstream, MSO_MAX_UNORDER, &mopt, sizeof(mopt)); if(ret < 0){ printf("\033[1;31;40mMESA_set_stream_opt():set max_unorder option error!\033[0m\n"); @@ -138,7 +138,7 @@ extern "C" char ctrl_takeover_exclusive_entry(struct streaminfo *pstream,void ** if(tcp_exclusive_entry_pkt_num >= 68){ if(0 == tcp_plundered_entry_pkt_num){ - /* 此函数挂载到TCPALL入库, 设置takeover标志后, + /* 此函数挂载到TCPALL入库, 设置takeover标志�?, ctrl_takeover_plundered_entry一个包应该都收不到 */ sendto_test_result(GTEST_SAPP_SUCC); @@ -580,7 +580,7 @@ extern "C" char project_customer_entry(struct streaminfo *pstream,void **pme, in extern "C" char project_producer_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet) { if(OP_STATE_PENDING == pstream->pktstate){ -#if 0 //v4.2版本后, 支持动态自动注册,不用写project_list.conf, 但是标签注册必须在初始化阶段, +#if 0 //v4.2版本�?, 支持动态自动注�?,不用写project_list.conf, 但是标签注册必须在初始化阶段, project_test_id = project_producer_register(project_name, "int", NULL); if(project_test_id < 0){ printf("\033[1;31;40mproject_producer_register error!\033[0m\n"); @@ -601,7 +601,7 @@ extern "C" int project_test_init(void) return -1; } - //v4.2版本后, 支持动态自动注册,不用写project_list.conf, 但是标签注册必须在初始化阶段, + //v4.2版本�?, 支持动态自动注�?,不用写project_list.conf, 但是标签注册必须在初始化阶段, project_test_id = project_producer_register(project_name, "int", NULL); if(project_test_id < 0){ printf("\033[1;31;40mproject_producer_register error!\033[0m\n"); @@ -639,7 +639,7 @@ extern "C" int project_notify_cb2(const struct streaminfo *stream, int project_r extern "C" char project_customer_no_result_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet) { - /* 此处插件不发送正确结果, 只判断错误 */ + /* 此处插件不发送正确结�?, 只判断错�? */ int res; res = project_req_get_int(pstream, project_test_id); @@ -657,7 +657,7 @@ extern "C" char project_customer_no_result_entry(struct streaminfo *pstream,void extern "C" char project_customer_entry1(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet) { int res; - /* 此处插件不发送正确结果, 只判断错误 */ + /* 此处插件不发送正确结�?, 只判断错�? */ res = project_req_get_int(pstream, project_notify_plug1_id); if(0x12345678 != res){ @@ -673,7 +673,7 @@ extern "C" char project_customer_entry1(struct streaminfo *pstream,void **pme, i extern "C" char project_customer_entry2(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet) { int res; - /* 第2个插件排在最后, 如果都正确, 则发送正确结果 */ + /* �?2个插件排在最�?, 如果都正�?, 则发送正确结�? */ res = project_req_get_int(pstream, project_notify_plug2_id); if(0x12345678 == res){ @@ -741,7 +741,7 @@ void sapp_timer_test_cbfun(sapp_timer_handle h, sapp_timer_event ev, int pkt_pro if(gtest_ctrl_tcp_stat.C2S_all_pkt >= 10){ diff = time(NULL) - first_call_time; - if(diff >= 9){ /* 理论上收到10个包, 也是延迟10秒, 允许一点误差, 此处判断9秒 */ + if(diff >= 9){ /* 理论上收�?10个包, 也是延迟10�?, 允许一点误�?, 此处判断9�? */ SAPP_PLUG_LOG(RLOG_LV_INFO, "timer.simple","timer_test succ! time pass %lds, call entry %u times!\n", diff, gtest_ctrl_tcp_stat.C2S_all_pkt); gtest_set_libsapp_devel_result(GTEST_SAPP_SUCC); memset(>est_ctrl_tcp_stat, 0, sizeof(gtest_plug_stat_t)); @@ -849,13 +849,13 @@ extern "C" char global_stream_id_tcpall_entry(struct streaminfo *pstream,void ** unsigned long long ts_from_sapp = (sapp_global_id & 0x07ffffff8000) >> 15; if(ts_from_sapp > ts_from_time){ - if(ts_from_sapp > ts_from_time + 1){ /* 允许误差1秒 */ + if(ts_from_sapp > ts_from_time + 1){ /* 允许误差1�? */ printf("\033[1;31;40mtimestamp from sapp error!\033[0m\n"); sendto_test_result(GTEST_SAPP_ERR); return APP_STATE_DROPME; } }else{ - if(ts_from_time > ts_from_sapp + 1){ /* 允许误差1秒 */ + if(ts_from_time > ts_from_sapp + 1){ /* 允许误差1�? */ printf("\033[1;31;40mtimestamp from sapp error!\033[0m\n"); sendto_test_result(GTEST_SAPP_ERR); return APP_STATE_DROPME; @@ -870,7 +870,7 @@ extern "C" char global_stream_id_tcpall_entry(struct streaminfo *pstream,void ** /* - 读取tcp_tuple4_reuse.pcap, 应该有两个流被先后调用, stream_id应该生成两个不同的值. + 读取tcp_tuple4_reuse.pcap, 应该有两个流被先后调�?, stream_id应该生成两个不同的�?. */ static int test_stream_id_num = 0; static unsigned long long test_last_stream_id = 0; @@ -914,7 +914,7 @@ extern "C" char global_stream_id_tuple4_reuse_tcpall_entry(struct streaminfo *ps /* - 读取tcp_tuple4_reuse.pcap, 应该有两个流被先后调用, stream tcpdetail createtime应该有两个值. + 读取tcp_tuple4_reuse.pcap, 应该有两个流被先后调�?, stream tcpdetail createtime应该有两个�?. */ static int test_reuse_stream_num = 0; static time_t first_stream_creatime, second_stream_creatime; @@ -928,7 +928,7 @@ extern "C" char stream_creatime_tuple4_reuse_tcpall_entry(struct streaminfo *pst first_stream_creatime = pstream->ptcpdetail->createtime; MESA_get_stream_opt(pstream, MSO_STREAM_CREATE_TIMESTAMP_MS, &first_stream_creatime_ms, &opt_len); }else{ - /* 记录四元组重用, 第2个流的时间 */ + /* 记录四元组重�?, �?2个流的时�? */ second_stream_creatime = pstream->ptcpdetail->createtime; MESA_get_stream_opt(pstream, MSO_STREAM_CREATE_TIMESTAMP_MS, &second_stream_creatime_ms, &opt_len); @@ -1053,7 +1053,7 @@ extern "C" char stream_createtime_ms_tcpall_entry(struct streaminfo *pstream,voi } - if(OP_STATE_CLOSE == pstream->pktstate){ /* 结束的时候再获取一遍 */ + if(OP_STATE_CLOSE == pstream->pktstate){ /* 结束的时候再获取一�? */ ret = MESA_get_stream_opt(pstream, MSO_STREAM_CREATE_TIMESTAMP_MS, &create_time_ms_close, &opt_len); if(ret < 0){ printf("\033[1;31;40mMESA_get_stream_opt()->MSO_STREAM_CREATE_TIMESTAMP_MS error!\033[0m\n"); @@ -1099,7 +1099,7 @@ extern "C" char up_layer_tunnel_gtp_entry(struct streaminfo *pstream,void **pme, if(OP_STATE_CLOSE != pstream->pktstate){ MESA_get_stream_opt(pstream, MSO_STREAM_UP_LAYER_TUNNEL_TYPE, &up_layer_tunnel_type, &opt_len); - if(STREAM_TUNNEL_GPRS_TUNNEL != up_layer_tunnel_type){ /* 此处要精确判断隧道类型, 防止解析出错, 不能用STREAM_TUNNLE_NON模糊判断 */ + if(STREAM_TUNNEL_GPRS_TUNNEL != up_layer_tunnel_type){ /* 此处要精确判断隧道类�?, 防止解析出错, 不能用STREAM_TUNNLE_NON模糊判断 */ g_up_layer_non_num++; }else{ g_up_layer_is_tunnel_num++; @@ -1108,7 +1108,7 @@ extern "C" char up_layer_tunnel_gtp_entry(struct streaminfo *pstream,void **pme, printf("stream: %s, tunnel:%d\n", printaddr(&pstream->addr, thread_seq), (int)up_layer_tunnel_type); } - if(13 == g_up_layer_plug_call_times){ /* gtp_dns.pcap一共5个包, 5个外层udp, 5个内层udp, 外加3个流的close状态, 最终是调用本插件entry 13次 */ + if(13 == g_up_layer_plug_call_times){ /* gtp_dns.pcap一�?5个包, 5个外层udp, 5个内层udp, 外加3个流的close状�?, 最终是调用本插件entry 13�? */ if((5 == g_up_layer_non_num) && (5 == g_up_layer_is_tunnel_num)){ printf("\033[32mup_layer_tunnel_gtp test success!\033[0m\n"); sendto_test_result(GTEST_SAPP_SUCC); @@ -1131,7 +1131,7 @@ extern "C" char up_layer_tunnel_l2tp_entry(struct streaminfo *pstream,void **pme if(OP_STATE_CLOSE != pstream->pktstate){ MESA_get_stream_opt(pstream, MSO_STREAM_UP_LAYER_TUNNEL_TYPE, &up_layer_tunnel_type, &opt_len); - if(STREAM_TUNNLE_L2TP != up_layer_tunnel_type){ /* 此处要精确判断隧道类型, 防止解析出错, 不能用STREAM_TUNNLE_NON模糊判断 */ + if(STREAM_TUNNLE_L2TP != up_layer_tunnel_type){ /* 此处要精确判断隧道类�?, 防止解析出错, 不能用STREAM_TUNNLE_NON模糊判断 */ g_up_layer_non_num++; }else{ g_up_layer_is_tunnel_num++; @@ -1140,7 +1140,7 @@ extern "C" char up_layer_tunnel_l2tp_entry(struct streaminfo *pstream,void **pme printf("stream: %s, tunnel:%d\n", printaddr(&pstream->addr, thread_seq), (int)up_layer_tunnel_type); } - if(11 == g_up_layer_plug_call_times){ /* l2tp_dns.pcap一共4个包, 4个外层udp, 4个内层udp, 外加3个流的close状态, 最终是调用本插件entry 11次 */ + if(11 == g_up_layer_plug_call_times){ /* l2tp_dns.pcap一�?4个包, 4个外层udp, 4个内层udp, 外加3个流的close状�?, 最终是调用本插件entry 11�? */ if((4 == g_up_layer_non_num) && (4 == g_up_layer_is_tunnel_num)){ sendto_test_result(GTEST_SAPP_SUCC); }else{ @@ -1161,7 +1161,7 @@ extern "C" char up_layer_tunnel_teredo_entry(struct streaminfo *pstream,void **p if(OP_STATE_CLOSE != pstream->pktstate){ MESA_get_stream_opt(pstream, MSO_STREAM_UP_LAYER_TUNNEL_TYPE, &up_layer_tunnel_type, &opt_len); - if(STREAM_TUNNLE_TEREDO != up_layer_tunnel_type){ /* 此处要精确判断隧道类型, 防止解析出错, 不能用STREAM_TUNNLE_NON模糊判断 */ + if(STREAM_TUNNLE_TEREDO != up_layer_tunnel_type){ /* 此处要精确判断隧道类�?, 防止解析出错, 不能用STREAM_TUNNLE_NON模糊判断 */ g_up_layer_non_num++; }else{ g_up_layer_is_tunnel_num++; @@ -1170,7 +1170,7 @@ extern "C" char up_layer_tunnel_teredo_entry(struct streaminfo *pstream,void **p printf("stream: %s, tunnel:%d\n", printaddr(&pstream->addr, thread_seq), (int)up_layer_tunnel_type); } - if(10 == g_up_layer_plug_call_times){ /* teredo_udp.pcap一共3个包, 3个外层udp, 3个内层udp, 外加4个流的close状态, 最终是调用本插件entry 10次 */ + if(10 == g_up_layer_plug_call_times){ /* teredo_udp.pcap一�?3个包, 3个外层udp, 3个内层udp, 外加4个流的close状�?, 最终是调用本插件entry 10�? */ if((3 == g_up_layer_non_num) && (3 == g_up_layer_is_tunnel_num)){ sendto_test_result(GTEST_SAPP_SUCC); }else{ @@ -1186,19 +1186,19 @@ extern "C" char up_layer_tunnel_teredo_entry(struct streaminfo *pstream,void **p extern "C" int get_plug_pme_init(void) { - /* 此处每个插件都要初始化一遍, 因为dlopen时业务层插件加载方式是RTLD_LOCAL, 看似一个全局变量gtest_slave_plug_fd, 实际上地址是不一样的 */ + /* 此处每个插件都要初始化一�?, 因为dlopen时业务层插件加载方式是RTLD_LOCAL, 看似一个全局变量gtest_slave_plug_fd, 实际上地址是不一样的 */ gtest_sapp_slave_init(); return 0; } -/* 空函数, 啥也不干, 只是挂载这个层的一个插件 */ +/* 空函�?, 啥也不干, 只是挂载这个层的一个插�? */ extern "C" char void_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet) { return APP_STATE_GIVEME; } -/* 挂载到tcpall层入口,只处理本插件自身的pme */ +/* 挂载到tcpall层入�?,只处理本插件自身的pme */ extern "C" char get_plug_pme_tcpall_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet) { int ret; @@ -1206,7 +1206,7 @@ extern "C" char get_plug_pme_tcpall_entry(struct streaminfo *pstream,void **pme, struct mso_plug_pme mso_plug_pme1 = {}; int opt_val_len; - /* 此处插件不发送正确结果, 只判断错误 */ + /* 此处插件不发送正确结�?, 只判断错�? */ if(OP_STATE_PENDING == pstream->opstate){ plug1_pme = (int *)malloc(sizeof(int)); *plug1_pme = 0x11111111; @@ -1244,7 +1244,7 @@ extern "C" char get_plug_pme_tcpall_entry(struct streaminfo *pstream,void **pme, return APP_STATE_GIVEME; } -/* tcp插件最后被调用, 需要验证tcpall和udp插件的Pme获取状态 */ +/* tcp插件最后被调用, 需要验证tcpall和udp插件的Pme获取状�? */ extern "C" char get_plug_pme_tcp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet) { int ret; @@ -1310,7 +1310,7 @@ extern "C" char get_plug_pme_tcp_entry(struct streaminfo *pstream,void **pme, in } -/* 挂载到udp层入口,只处理本插件自身的pme */ +/* 挂载到udp层入�?,只处理本插件自身的pme */ extern "C" char get_plug_pme_udp_entry1(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet) { int ret; @@ -1318,7 +1318,7 @@ extern "C" char get_plug_pme_udp_entry1(struct streaminfo *pstream,void **pme, i struct mso_plug_pme mso_plug_pme1 = {}; int opt_val_len; - /* 此处插件不发送正确结果, 只判断错误 */ + /* 此处插件不发送正确结�?, 只判断错�? */ if(OP_STATE_PENDING == pstream->opstate){ plug1_pme = (int *)malloc(sizeof(int)); *plug1_pme = 0x11111111; @@ -1356,7 +1356,7 @@ extern "C" char get_plug_pme_udp_entry1(struct streaminfo *pstream,void **pme, i return APP_STATE_GIVEME; } -/* udp2插件最后被调用, 需要验证udp1插件的Pme获取状态 */ +/* udp2插件最后被调用, 需要验证udp1插件的Pme获取状�? */ extern "C" char get_plug_pme_udp_entry2(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet) { int ret; @@ -1416,7 +1416,7 @@ extern "C" char get_plug_pme_udp_entry2(struct streaminfo *pstream,void **pme, i if(OP_STATE_CLOSE == pstream->opstate){ free(*pme); - /* 正确结果在 get_plug_pme_tcp_entry() 函数中发送 */ + /* 正确结果�? get_plug_pme_tcp_entry() 函数中发�? */ //printf("\033[32mget_plug_pme_entry test success!\033[0m\n"); //sendto_test_result(GTEST_SAPP_SUCC); } @@ -1437,7 +1437,7 @@ extern "C" char get_duplicate_pkt_stat_entry(struct streaminfo *pstream,void **p } - /* pending状态的第一个包, 不可能是1也不可能是0, 只能是-2 */ + /* pending状态的第一个包, 不可能是1也不可能�?0, 只能�?-2 */ if(has_dup_pkt != -2){ printf("\033[1;31;40mget_duplicate_pkt_stat_entry(), first packet get MSO_HAVE_DUP_PKT is true!\033[0m\n"); sendto_test_result(GTEST_SAPP_ERR); @@ -1484,11 +1484,11 @@ extern "C" char tcp_bridge_producer_entry(struct streaminfo *pstream,void **pme, async_data = (char *)malloc(strlen(TEST_BRIDGE_ASYNC_DATA) + 1); strcpy(async_data, TEST_BRIDGE_ASYNC_DATA); stream_bridge_async_data_put(pstream, bridge_id, async_data); - stream_bridge_sync_data_put(pstream, bridge_id, (void *)TEST_BRIDGE_SYNC_DATA); /* 第一次customer收不到, 因为customer还没有注册 */ + stream_bridge_sync_data_put(pstream, bridge_id, (void *)TEST_BRIDGE_SYNC_DATA); /* 第一次customer收不�?, 因为customer还没有注�? */ }else if(OP_STATE_DATA == pstream->opstate){ stream_bridge_sync_data_put(pstream, bridge_id, (void *)TEST_BRIDGE_SYNC_DATA); }else{ - ; /* customer2最后被调用, 测试结果在customer2发送 */ + ; /* customer2最后被调用, 测试结果在customer2发�? */ } return APP_STATE_GIVEME; @@ -1540,11 +1540,11 @@ extern "C" char tcp_bridge_customer1_entry(struct streaminfo *pstream,void **pme } - if(g_test_stream_bridge_sync_call_num1 != 46){ /* tcp_simple.pcap有46个负载包 */ + if(g_test_stream_bridge_sync_call_num1 != 46){ /* tcp_simple.pcap�?46个负载包 */ printf("\033[1;31;40mtcp_bridge_customer1_entry() sync call number error!\033[0m\n"); sendto_test_result(GTEST_SAPP_ERR); - } /* customer2最后被调用, 是否成功的结果在customer2里发送 */ + } /* customer2最后被调用, 是否成功的结果在customer2里发�? */ } return APP_STATE_GIVEME; @@ -1567,7 +1567,7 @@ extern "C" char tcp_bridge_customer2_entry(struct streaminfo *pstream,void **pme } - if(g_test_stream_bridge_sync_call_num2 != 46){ /* tcp_simple.pcap有46个负载包 */ + if(g_test_stream_bridge_sync_call_num2 != 46){ /* tcp_simple.pcap�?46个负载包 */ printf("\033[1;31;40mtcp_bridge_customer2_entry() sync call number error!\033[0m\n"); sendto_test_result(GTEST_SAPP_ERR); @@ -1837,7 +1837,7 @@ extern "C" int find_streaminfo_by_addrv4(int thread_index, const struct stream_t extern "C" int find_streaminfo_by_addrv6(int thread_index, const struct stream_tuple4_v6 *tuplev6, enum stream_type_t streamtype, struct streaminfo *streaminfo_array[], int array_max_num); /* - 通过四元组查找streaminfo, 在一堆pcap里, 随机找四个流, 两个tcp, 两个udp , + 通过四元组查找streaminfo, 在一堆pcap�?, 随机找四个流, 两个tcp, 两个udp , 两个方向分别查询, C2S和S2C. */ extern "C" char polling_find_streaminfo_entry_v4(struct streaminfo *nouse,void **nouse2, int thread_seq, void *nouse3) @@ -1927,7 +1927,7 @@ extern "C" char polling_find_streaminfo_entry_v4(struct streaminfo *nouse,void * } - /************ 此处故意写个错的四元组, ip和port顺序反了, 理论上应该是查不到的 */ + /************ 此处故意写个错的四元�?, ip和port顺序反了, 理论上应该是查不到的 */ find_streaminfo_build_tuple4v4(&t4v4, "192.168.36.103", "125.94.242.80", 20001, 57232); result_num = find_streaminfo_by_addrv4(thread_seq, &t4v4, STREAM_TYPE_TCP, result, 10); if(result_num > 0){ @@ -1940,7 +1940,7 @@ extern "C" char polling_find_streaminfo_entry_v4(struct streaminfo *nouse,void * /* - 通过四元组查找streaminfo, 在一堆pcap里, 随机找四个流, 两个tcp, 两个udp , + 通过四元组查找streaminfo, 在一堆pcap�?, 随机找四个流, 两个tcp, 两个udp , 两个方向分别查询, C2S和S2C. */ extern "C" char polling_find_streaminfo_entry_v6(struct streaminfo *nouse,void **nouse2, int thread_seq, void *nouse3) @@ -2039,7 +2039,7 @@ extern "C" char polling_find_streaminfo_entry_v6(struct streaminfo *nouse,void * } - /************ 此处故意写个错的四元组, ip和port顺序反了, 理论上应该是查不到的 */ + /************ 此处故意写个错的四元�?, ip和port顺序反了, 理论上应该是查不到的 */ find_streaminfo_build_tuple4v6(&t4v6, "2001::192:168:40:162", "2001::192:168:40:161", 44444, 39410); result_v6_num = find_streaminfo_by_addrv6(thread_seq, &t4v6, STREAM_TYPE_TCP, result_v6, 10); if(result_v6_num > 0){ @@ -2052,7 +2052,7 @@ extern "C" char polling_find_streaminfo_entry_v6(struct streaminfo *nouse,void * } /* - 内层四元组一样, 但外层不一样的四元组地址查询. + 内层四元组一�?, 但外层不一样的四元组地址查询. */ extern "C" char polling_find_diff_tunnel_streaminfo_entry_v4(struct streaminfo *nouse,void **nouse2, int thread_seq, void *nouse3) { @@ -2138,7 +2138,7 @@ extern "C" char fork_listen_port_tcp_plug(struct streaminfo *pstream,void **pme, printf("fork_listen_port child pid:%d\n", getpid()); usleep(10000); /* 子进程等父sapp进程彻底结束 */ - /* 再次执行一次sapp, 保证不能再打开12345等监听端口, 且使用在线模式, 不退出 */ + /* 再次执行一次sapp, 保证不能再打开12345等监听端�?, 且使用在线模�?, 不退�? */ update_config_file_by_lastline("etc/sapp.toml", "packet_io.deployment", "mode", "mirror"); update_config_file_by_lastNline("etc/sapp.toml", "packet_io.internal.interface", 1, "name", "lo"); @@ -2161,7 +2161,7 @@ extern "C" char fork_listen_port_tcp_plug(struct streaminfo *pstream,void **pme, printf("\033[1;31;40mfork_listen_port plug error: execv sapp fail!\033[0m\n"); }else{ printf("fork_listen_port parent pid:%d, exit!\n", getpid()); - /* sapp父进程退出 */ + /* sapp父进程退�? */ } } @@ -2297,7 +2297,7 @@ static char __get_deployment_mode_entry(struct streaminfo *pstream,void **pme, i return APP_STATE_DROPME; } - /* 用了一个插件入口函数, 使用不同的dumpfile来表示不同的拓扑模式 */ + /* 用了一个插件入口函�?, 使用不同的dumpfile来表示不同的拓扑模式 */ gtest_file_md5sum("dumpfile", file_md5, sizeof(file_md5)); if(strncasecmp(file_md5, "df138740a6a22ca9c977052f21f7a470", strlen("df138740a6a22ca9c977052f21f7a470")) == 0){ if(dep_mode != DEPLOYMENT_MODE_MIRROR){ @@ -2380,10 +2380,10 @@ extern "C" int plug_necessary_init(void) return -1; /* 测试necessary_plug_list功能, 故意初始化不成功 */ } -/* 排在necessary插件后面, 也不应该被调用 */ +/* 排在necessary插件后面, 也不应该被调�? */ extern "C" int plug_indifferent_init(void) { - gtest_sapp_slave_init(); /* 每个插件有独立的符号名, 需要独立调用gtest_sapp_slave_init()函数, 创建socket, 否则发送结果会失败 */ + gtest_sapp_slave_init(); /* 每个插件有独立的符号�?, 需要独立调用gtest_sapp_slave_init()函数, 创建socket, 否则发送结果会失败 */ printf("\033[1;31;40mnecessary plug init error, can't call this function!\033[0m\n"); sendto_test_result(GTEST_SAPP_ERR); @@ -2393,13 +2393,13 @@ extern "C" int plug_indifferent_init(void) extern "C" char plug_necessary_not_call_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet) { - gtest_sapp_slave_init(); /* 每个插件有独立的符号名, 需要独立调用gtest_sapp_slave_init()函数, 创建socket, 否则发送结果会失败 */ + gtest_sapp_slave_init(); /* 每个插件有独立的符号�?, 需要独立调用gtest_sapp_slave_init()函数, 创建socket, 否则发送结果会失败 */ printf("\033[1;31;40minit error, can't call this entry!\033[0m\n"); sendto_test_result(GTEST_SAPP_ERR); return APP_STATE_GIVEME; } -/* 排在necessary插件后面, 也不应该被调用 */ +/* 排在necessary插件后面, 也不应该被调�? */ extern "C" char plug_indifferent_not_call_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet) { printf("\033[1;31;40mnecessary plug init error, can't call this entry!\033[0m\n"); @@ -2553,6 +2553,41 @@ extern "C" char get_tcp_rtt_err_entry(struct streaminfo *pstream, void **pme, in return APP_STATE_GIVEME; } +extern "C" char ctrl_get_stream_uuid_entry(struct streaminfo *pstream, void **pme, int thread_seq, void *a_packet) +{ + static unsigned char uuid[16] = {0}; + int opt_len = sizeof(uuid); + + if(OP_STATE_PENDING == pstream->opstate){ + MESA_get_stream_opt(pstream, MSO_STREAM_UUID, uuid, &opt_len); + } + if(OP_STATE_DATA == pstream->opstate){ + unsigned char uuid_data[16] = {0}; + MESA_get_stream_opt(pstream, MSO_STREAM_UUID, uuid_data, &opt_len); + if(memcmp(uuid, uuid_data, 16) != 0){ + fprintf(stderr, "\033[1;31;40mctrl_get_stream_uuid_entry error: get uuid error!\033[0m\n"); + gtest_set_libsapp_devel_result(GTEST_SAPP_ERR); + return APP_STATE_DROPME; + } + } + + if(OP_STATE_CLOSE == pstream->opstate){ + unsigned char uuid_close[16] = {0}; + MESA_get_stream_opt(pstream, MSO_STREAM_UUID, uuid_close, &opt_len); + if(memcmp(uuid, uuid_close, 16) != 0){ + fprintf(stderr, "\033[1;31;40mctrl_get_stream_uuid_entry error: get uuid error!\033[0m\n"); + gtest_set_libsapp_devel_result(GTEST_SAPP_ERR); + return APP_STATE_DROPME; + } + + fprintf(stderr, "\033[32mctrl_get_stream_uuid_entry test succ \033[0m\n"); + gtest_set_libsapp_devel_result(GTEST_SAPP_SUCC); + return APP_STATE_DROPME; + } + + return APP_STATE_GIVEME; +} + #endif diff --git a/src/dealpkt/CMakeLists.txt b/src/dealpkt/CMakeLists.txt index 1215798..78fb60a 100644 --- a/src/dealpkt/CMakeLists.txt +++ b/src/dealpkt/CMakeLists.txt @@ -8,6 +8,7 @@ include_directories(${CMAKE_SOURCE_DIR}/src/support/dablooms/src) include_directories(${MESA_SDK_PREFIX}/include) include_directories(${MESA_SDK_PREFIX}/include/MESA) include_directories(${CMAKE_SOURCE_DIR}/src/support/ap_bloom/src) +include_directories(${CMAKE_SOURCE_DIR}/src/support/) if(OPT_IOMODE_MARSIO) include_directories(${MARSIO_SDK_PREFIX}/include) @@ -22,4 +23,4 @@ deal_arp.c deal_ipv6.c deal_ppp.c deal_teredo.c ip_reassembly.c deal_ethernet.c deal_pppoe.c deal_udp.c stream_manage.c deal_gre.c deal_l2tp.c deal_pptp.c deal_vlan.c deal_icmp.c deal_mac_in_mac.c deal_proxy.c g_device.c -deal_gprs_tunnel.c deal_vxlan.c duplicate_pkt_distinguish.c) +deal_gprs_tunnel.c deal_vxlan.c duplicate_pkt_distinguish.c)
\ No newline at end of file diff --git a/src/dealpkt/plug_support.c b/src/dealpkt/plug_support.c index c2b3256..0542394 100644 --- a/src/dealpkt/plug_support.c +++ b/src/dealpkt/plug_support.c @@ -8,6 +8,7 @@ #ifdef __cplusplus
extern "C" {
#endif
+#include "ulid/ulid_wrap.h"
extern int G_TCP_FLOW_STAT_PROJECT_ID ;
extern int G_UDP_FLOW_STAT_PROJECT_ID ;
@@ -2172,6 +2173,24 @@ int MESA_get_stream_opt(const struct streaminfo *pstream, enum MESA_stream_opt o }
break;
+ case MSO_STREAM_UUID:
+ {
+ if(*opt_val_len != sizeof(uuid_t)){
+ return -1;
+ }
+ if(uuid_is_null(pstream_pr->stream_uuid)){
+ ulid_uuid_generate(pstream_pr->stream_uuid);
+ if (MESA_handle_runtime_log_level_enabled(ABBR_SAPP_LOG_HANDLE, RLOG_LV_DEBUG)){
+ char uuid_string_buf[UUID_STR_LEN] = {0};
+ uuid_unparse(pstream_pr->stream_uuid, uuid_string_buf);
+ sapp_runtime_log(RLOG_LV_DEBUG, "%s, stream uuid: %s\n", printaddr(&pstream->addr, pstream->threadnum), uuid_string_buf);
+ }
+ }
+ memcpy(opt_val, pstream_pr->stream_uuid, sizeof(uuid_t));
+ ret = 0;
+ }
+ break;
+
default:
sapp_runtime_log(RLOG_LV_INFO, "%s,MESA_get_stream_opt() error:unsupport MESA_stream_opt type:%d!\n",printaddr(&pstream->addr, pstream->threadnum), (int)opt);
ret = -1;
diff --git a/src/support/CMakeLists.txt b/src/support/CMakeLists.txt index 469ea38..7d39256 100644 --- a/src/support/CMakeLists.txt +++ b/src/support/CMakeLists.txt @@ -12,3 +12,4 @@ add_subdirectory(dablooms) add_subdirectory(timeout) add_subdirectory(token_bucket) add_subdirectory(ap_bloom) +add_subdirectory(ulid)
\ No newline at end of file diff --git a/src/support/ulid/CMakeLists.txt b/src/support/ulid/CMakeLists.txt new file mode 100644 index 0000000..cbd82d0 --- /dev/null +++ b/src/support/ulid/CMakeLists.txt @@ -0,0 +1,3 @@ +suppress_cppcheck_in_current_dir() +add_definitions(-D_DEFAULT_SOURCE -D_GNU_SOURCE -D__DEFAULT_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H -fPIC) +add_library(ulid ulid_wrap.cpp) diff --git a/src/support/ulid/ulid_struct.hh b/src/support/ulid/ulid_struct.hh new file mode 100644 index 0000000..0345e30 --- /dev/null +++ b/src/support/ulid/ulid_struct.hh @@ -0,0 +1,708 @@ +#ifndef ULID_STRUCT_HH +#define ULID_STRUCT_HH + +#include <chrono> +#include <cstdlib> +#include <ctime> +#include <functional> +#include <random> +#include <vector> + +#if _MSC_VER > 0 +typedef uint32_t rand_t; +# else +typedef uint8_t rand_t; +#endif + +namespace ulid { + +/** + * ULID is a 16 byte Universally Unique Lexicographically Sortable Identifier + * */ +struct ULID { + uint8_t data[16]; + + ULID() { + // for (int i = 0 ; i < 16 ; i++) { + // data[i] = 0; + // } + + // unrolled loop + data[0] = 0; + data[1] = 0; + data[2] = 0; + data[3] = 0; + data[4] = 0; + data[5] = 0; + data[6] = 0; + data[7] = 0; + data[8] = 0; + data[9] = 0; + data[10] = 0; + data[11] = 0; + data[12] = 0; + data[13] = 0; + data[14] = 0; + data[15] = 0; + } + + ULID(uint64_t val) { + // for (int i = 0 ; i < 16 ; i++) { + // data[15 - i] = static_cast<uint8_t>(val); + // val >>= 8; + // } + + // unrolled loop + data[15] = static_cast<uint8_t>(val); + + val >>= 8; + data[14] = static_cast<uint8_t>(val); + + val >>= 8; + data[13] = static_cast<uint8_t>(val); + + val >>= 8; + data[12] = static_cast<uint8_t>(val); + + val >>= 8; + data[11] = static_cast<uint8_t>(val); + + val >>= 8; + data[10] = static_cast<uint8_t>(val); + + val >>= 8; + data[9] = static_cast<uint8_t>(val); + + val >>= 8; + data[8] = static_cast<uint8_t>(val); + + data[7] = 0; + data[6] = 0; + data[5] = 0; + data[4] = 0; + data[3] = 0; + data[2] = 0; + data[1] = 0; + data[0] = 0; + } + + ULID(const ULID& other) { + // for (int i = 0 ; i < 16 ; i++) { + // data[i] = other.data[i]; + // } + + // unrolled loop + data[0] = other.data[0]; + data[1] = other.data[1]; + data[2] = other.data[2]; + data[3] = other.data[3]; + data[4] = other.data[4]; + data[5] = other.data[5]; + data[6] = other.data[6]; + data[7] = other.data[7]; + data[8] = other.data[8]; + data[9] = other.data[9]; + data[10] = other.data[10]; + data[11] = other.data[11]; + data[12] = other.data[12]; + data[13] = other.data[13]; + data[14] = other.data[14]; + data[15] = other.data[15]; + } + + ULID& operator=(const ULID& other) { + // for (int i = 0 ; i < 16 ; i++) { + // data[i] = other.data[i]; + // } + + // unrolled loop + data[0] = other.data[0]; + data[1] = other.data[1]; + data[2] = other.data[2]; + data[3] = other.data[3]; + data[4] = other.data[4]; + data[5] = other.data[5]; + data[6] = other.data[6]; + data[7] = other.data[7]; + data[8] = other.data[8]; + data[9] = other.data[9]; + data[10] = other.data[10]; + data[11] = other.data[11]; + data[12] = other.data[12]; + data[13] = other.data[13]; + data[14] = other.data[14]; + data[15] = other.data[15]; + + return *this; + } + + ULID(ULID&& other) { + // for (int i = 0 ; i < 16 ; i++) { + // data[i] = other.data[i]; + // other.data[i] = 0; + // } + + // unrolled loop + data[0] = other.data[0]; + other.data[0] = 0; + + data[1] = other.data[1]; + other.data[1] = 0; + + data[2] = other.data[2]; + other.data[2] = 0; + + data[3] = other.data[3]; + other.data[3] = 0; + + data[4] = other.data[4]; + other.data[4] = 0; + + data[5] = other.data[5]; + other.data[5] = 0; + + data[6] = other.data[6]; + other.data[6] = 0; + + data[7] = other.data[7]; + other.data[7] = 0; + + data[8] = other.data[8]; + other.data[8] = 0; + + data[9] = other.data[9]; + other.data[9] = 0; + + data[10] = other.data[10]; + other.data[10] = 0; + + data[11] = other.data[11]; + other.data[11] = 0; + + data[12] = other.data[12]; + other.data[12] = 0; + + data[13] = other.data[13]; + other.data[13] = 0; + + data[14] = other.data[14]; + other.data[14] = 0; + + data[15] = other.data[15]; + other.data[15] = 0; + } + + ULID& operator=(ULID&& other) { + // for (int i = 0 ; i < 16 ; i++) { + // data[i] = other.data[i]; + // other.data[i] = 0; + // } + + // unrolled loop + data[0] = other.data[0]; + other.data[0] = 0; + + data[1] = other.data[1]; + other.data[1] = 0; + + data[2] = other.data[2]; + other.data[2] = 0; + + data[3] = other.data[3]; + other.data[3] = 0; + + data[4] = other.data[4]; + other.data[4] = 0; + + data[5] = other.data[5]; + other.data[5] = 0; + + data[6] = other.data[6]; + other.data[6] = 0; + + data[7] = other.data[7]; + other.data[7] = 0; + + data[8] = other.data[8]; + other.data[8] = 0; + + data[9] = other.data[9]; + other.data[9] = 0; + + data[10] = other.data[10]; + other.data[10] = 0; + + data[11] = other.data[11]; + other.data[11] = 0; + + data[12] = other.data[12]; + other.data[12] = 0; + + data[13] = other.data[13]; + other.data[13] = 0; + + data[14] = other.data[14]; + other.data[14] = 0; + + data[15] = other.data[15]; + other.data[15] = 0; + + return *this; + } +}; + +/** + * EncodeTime will encode the first 6 bytes of a uint8_t array to the passed + * timestamp + * */ +inline void EncodeTime(time_t timestamp, ULID& ulid) { + ulid.data[0] = static_cast<uint8_t>(timestamp >> 40); + ulid.data[1] = static_cast<uint8_t>(timestamp >> 32); + ulid.data[2] = static_cast<uint8_t>(timestamp >> 24); + ulid.data[3] = static_cast<uint8_t>(timestamp >> 16); + ulid.data[4] = static_cast<uint8_t>(timestamp >> 8); + ulid.data[5] = static_cast<uint8_t>(timestamp); +} + +/** + * EncodeTimeNow will encode a ULID using the time obtained using std::time(nullptr) + * */ +inline void EncodeTimeNow(ULID& ulid) { + EncodeTime(std::time(nullptr), ulid); +} + +/** + * EncodeTimeSystemClockNow will encode a ULID using the time obtained using + * std::chrono::system_clock::now() by taking the timestamp in milliseconds. + * */ +inline void EncodeTimeSystemClockNow(ULID& ulid) { + auto now = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()); + EncodeTime(ms.count(), ulid); +} + +/** + * EncodeEntropy will encode the last 10 bytes of the passed uint8_t array with + * the values generated using the passed random number generator. + * */ +inline void EncodeEntropy(const std::function<uint8_t()>& rng, ULID& ulid) { + ulid.data[6] = rng(); + ulid.data[7] = rng(); + ulid.data[8] = rng(); + ulid.data[9] = rng(); + ulid.data[10] = rng(); + ulid.data[11] = rng(); + ulid.data[12] = rng(); + ulid.data[13] = rng(); + ulid.data[14] = rng(); + ulid.data[15] = rng(); +} + +/** + * EncodeEntropyRand will encode a ulid using std::rand + * + * std::rand returns values in [0, RAND_MAX] + * */ +inline void EncodeEntropyRand(ULID& ulid) { + ulid.data[6] = (uint8_t)(std::rand() * 255ull) / RAND_MAX; + ulid.data[7] = (uint8_t)(std::rand() * 255ull) / RAND_MAX; + ulid.data[8] = (uint8_t)(std::rand() * 255ull) / RAND_MAX; + ulid.data[9] = (uint8_t)(std::rand() * 255ull) / RAND_MAX; + ulid.data[10] = (uint8_t)(std::rand() * 255ull) / RAND_MAX; + ulid.data[11] = (uint8_t)(std::rand() * 255ull) / RAND_MAX; + ulid.data[12] = (uint8_t)(std::rand() * 255ull) / RAND_MAX; + ulid.data[13] = (uint8_t)(std::rand() * 255ull) / RAND_MAX; + ulid.data[14] = (uint8_t)(std::rand() * 255ull) / RAND_MAX; + ulid.data[15] = (uint8_t)(std::rand() * 255ull) / RAND_MAX; +} + +static std::uniform_int_distribution<rand_t> Distribution_0_255(0, 255); + +/** + * EncodeEntropyMt19937 will encode a ulid using std::mt19937 + * + * It also creates a std::uniform_int_distribution to generate values in [0, 255] + * */ +inline void EncodeEntropyMt19937(std::mt19937& generator, ULID& ulid) { + ulid.data[6] = Distribution_0_255(generator); + ulid.data[7] = Distribution_0_255(generator); + ulid.data[8] = Distribution_0_255(generator); + ulid.data[9] = Distribution_0_255(generator); + ulid.data[10] = Distribution_0_255(generator); + ulid.data[11] = Distribution_0_255(generator); + ulid.data[12] = Distribution_0_255(generator); + ulid.data[13] = Distribution_0_255(generator); + ulid.data[14] = Distribution_0_255(generator); + ulid.data[15] = Distribution_0_255(generator); +} + +/** + * Encode will create an encoded ULID with a timestamp and a generator. + * */ +inline void Encode(time_t timestamp, const std::function<uint8_t()>& rng, ULID& ulid) { + EncodeTime(timestamp, ulid); + EncodeEntropy(rng, ulid); +} + +/** + * EncodeNowRand = EncodeTimeNow + EncodeEntropyRand. + * */ +inline void EncodeNowRand(ULID& ulid) { + EncodeTimeNow(ulid); + EncodeEntropyRand(ulid); +} + +/** + * Create will create a ULID with a timestamp and a generator. + * */ +inline ULID Create(time_t timestamp, const std::function<uint8_t()>& rng) { + ULID ulid; + Encode(timestamp, rng, ulid); + return ulid; +} + +/** + * CreateNowRand:EncodeNowRand = Create:Encode. + * */ +inline ULID CreateNowRand() { + ULID ulid; + EncodeNowRand(ulid); + return ulid; +} + +/** + * Crockford's Base32 + * */ +static const char Encoding[33] = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"; + +/** + * MarshalTo will marshal a ULID to the passed character array. + * + * Implementation taken directly from oklog/ulid + * (https://sourcegraph.com/github.com/oklog/ulid@0774f81f6e44af5ce5e91c8d7d76cf710e889ebb/-/blob/ulid.go#L162-190) + * + * timestamp:<br> + * dst[0]: first 3 bits of data[0]<br> + * dst[1]: last 5 bits of data[0]<br> + * dst[2]: first 5 bits of data[1]<br> + * dst[3]: last 3 bits of data[1] + first 2 bits of data[2]<br> + * dst[4]: bits 3-7 of data[2]<br> + * dst[5]: last bit of data[2] + first 4 bits of data[3]<br> + * dst[6]: last 4 bits of data[3] + first bit of data[4]<br> + * dst[7]: bits 2-6 of data[4]<br> + * dst[8]: last 2 bits of data[4] + first 3 bits of data[5]<br> + * dst[9]: last 5 bits of data[5]<br> + * + * entropy: + * follows similarly, except now all components are set to 5 bits. + * */ +inline void MarshalTo(const ULID& ulid, char dst[26]) { + // 10 byte timestamp + dst[0] = Encoding[(ulid.data[0] & 224) >> 5]; + dst[1] = Encoding[ulid.data[0] & 31]; + dst[2] = Encoding[(ulid.data[1] & 248) >> 3]; + dst[3] = Encoding[((ulid.data[1] & 7) << 2) | ((ulid.data[2] & 192) >> 6)]; + dst[4] = Encoding[(ulid.data[2] & 62) >> 1]; + dst[5] = Encoding[((ulid.data[2] & 1) << 4) | ((ulid.data[3] & 240) >> 4)]; + dst[6] = Encoding[((ulid.data[3] & 15) << 1) | ((ulid.data[4] & 128) >> 7)]; + dst[7] = Encoding[(ulid.data[4] & 124) >> 2]; + dst[8] = Encoding[((ulid.data[4] & 3) << 3) | ((ulid.data[5] & 224) >> 5)]; + dst[9] = Encoding[ulid.data[5] & 31]; + + // 16 bytes of entropy + dst[10] = Encoding[(ulid.data[6] & 248) >> 3]; + dst[11] = Encoding[((ulid.data[6] & 7) << 2) | ((ulid.data[7] & 192) >> 6)]; + dst[12] = Encoding[(ulid.data[7] & 62) >> 1]; + dst[13] = Encoding[((ulid.data[7] & 1) << 4) | ((ulid.data[8] & 240) >> 4)]; + dst[14] = Encoding[((ulid.data[8] & 15) << 1) | ((ulid.data[9] & 128) >> 7)]; + dst[15] = Encoding[(ulid.data[9] & 124) >> 2]; + dst[16] = Encoding[((ulid.data[9] & 3) << 3) | ((ulid.data[10] & 224) >> 5)]; + dst[17] = Encoding[ulid.data[10] & 31]; + dst[18] = Encoding[(ulid.data[11] & 248) >> 3]; + dst[19] = Encoding[((ulid.data[11] & 7) << 2) | ((ulid.data[12] & 192) >> 6)]; + dst[20] = Encoding[(ulid.data[12] & 62) >> 1]; + dst[21] = Encoding[((ulid.data[12] & 1) << 4) | ((ulid.data[13] & 240) >> 4)]; + dst[22] = Encoding[((ulid.data[13] & 15) << 1) | ((ulid.data[14] & 128) >> 7)]; + dst[23] = Encoding[(ulid.data[14] & 124) >> 2]; + dst[24] = Encoding[((ulid.data[14] & 3) << 3) | ((ulid.data[15] & 224) >> 5)]; + dst[25] = Encoding[ulid.data[15] & 31]; +} + +/** + * Marshal will marshal a ULID to a std::string. + * */ +inline std::string Marshal(const ULID& ulid) { + char data[27]; + data[26] = '\0'; + MarshalTo(ulid, data); + return std::string(data); +} + +/** + * MarshalBinaryTo will Marshal a ULID to the passed byte array + * */ +inline void MarshalBinaryTo(const ULID& ulid, uint8_t dst[16]) { + // timestamp + dst[0] = ulid.data[0]; + dst[1] = ulid.data[1]; + dst[2] = ulid.data[2]; + dst[3] = ulid.data[3]; + dst[4] = ulid.data[4]; + dst[5] = ulid.data[5]; + + // entropy + dst[6] = ulid.data[6]; + dst[7] = ulid.data[7]; + dst[8] = ulid.data[8]; + dst[9] = ulid.data[9]; + dst[10] = ulid.data[10]; + dst[11] = ulid.data[11]; + dst[12] = ulid.data[12]; + dst[13] = ulid.data[13]; + dst[14] = ulid.data[14]; + dst[15] = ulid.data[15]; +} + +/** + * MarshalBinary will Marshal a ULID to a byte vector. + * */ +inline std::vector<uint8_t> MarshalBinary(const ULID& ulid) { + std::vector<uint8_t> dst(16); + MarshalBinaryTo(ulid, dst.data()); + return dst; +} + +/** + * dec storesdecimal encodings for characters. + * 0xFF indicates invalid character. + * 48-57 are digits. + * 65-90 are capital alphabets. + * */ +static const uint8_t dec[256] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + /* 0 1 2 3 4 5 6 7 */ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + /* 8 9 */ + 0x08, 0x09, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + + /* 10(A) 11(B) 12(C) 13(D) 14(E) 15(F) 16(G) */ + 0xFF, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, + /*17(H) 18(J) 19(K) 20(M) 21(N) */ + 0x11, 0xFF, 0x12, 0x13, 0xFF, 0x14, 0x15, 0xFF, + /*22(P)23(Q)24(R) 25(S) 26(T) 27(V) 28(W) */ + 0x16, 0x17, 0x18, 0x19, 0x1A, 0xFF, 0x1B, 0x1C, + /*29(X)30(Y)31(Z) */ + 0x1D, 0x1E, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +}; + +/** + * UnmarshalFrom will unmarshal a ULID from the passed character array. + * */ +inline void UnmarshalFrom(const char str[26], ULID& ulid) { + // timestamp + ulid.data[0] = (dec[int(str[0])] << 5) | dec[int(str[1])]; + ulid.data[1] = (dec[int(str[2])] << 3) | (dec[int(str[3])] >> 2); + ulid.data[2] = (dec[int(str[3])] << 6) | (dec[int(str[4])] << 1) | (dec[int(str[5])] >> 4); + ulid.data[3] = (dec[int(str[5])] << 4) | (dec[int(str[6])] >> 1); + ulid.data[4] = (dec[int(str[6])] << 7) | (dec[int(str[7])] << 2) | (dec[int(str[8])] >> 3); + ulid.data[5] = (dec[int(str[8])] << 5) | dec[int(str[9])]; + + // entropy + ulid.data[6] = (dec[int(str[10])] << 3) | (dec[int(str[11])] >> 2); + ulid.data[7] = (dec[int(str[11])] << 6) | (dec[int(str[12])] << 1) | (dec[int(str[13])] >> 4); + ulid.data[8] = (dec[int(str[13])] << 4) | (dec[int(str[14])] >> 1); + ulid.data[9] = (dec[int(str[14])] << 7) | (dec[int(str[15])] << 2) | (dec[int(str[16])] >> 3); + ulid.data[10] = (dec[int(str[16])] << 5) | dec[int(str[17])]; + ulid.data[11] = (dec[int(str[18])] << 3) | (dec[int(str[19])] >> 2); + ulid.data[12] = (dec[int(str[19])] << 6) | (dec[int(str[20])] << 1) | (dec[int(str[21])] >> 4); + ulid.data[13] = (dec[int(str[21])] << 4) | (dec[int(str[22])] >> 1); + ulid.data[14] = (dec[int(str[22])] << 7) | (dec[int(str[23])] << 2) | (dec[int(str[24])] >> 3); + ulid.data[15] = (dec[int(str[24])] << 5) | dec[int(str[25])]; +} + +/** + * Unmarshal will create a new ULID by unmarshaling the passed string. + * */ +inline ULID Unmarshal(const std::string& str) { + ULID ulid; + UnmarshalFrom(str.c_str(), ulid); + return ulid; +} + +/** + * UnmarshalBinaryFrom will unmarshal a ULID from the passed byte array. + * */ +inline void UnmarshalBinaryFrom(const uint8_t b[16], ULID& ulid) { + // timestamp + ulid.data[0] = b[0]; + ulid.data[1] = b[1]; + ulid.data[2] = b[2]; + ulid.data[3] = b[3]; + ulid.data[4] = b[4]; + ulid.data[5] = b[5]; + + // entropy + ulid.data[6] = b[6]; + ulid.data[7] = b[7]; + ulid.data[8] = b[8]; + ulid.data[9] = b[9]; + ulid.data[10] = b[10]; + ulid.data[11] = b[11]; + ulid.data[12] = b[12]; + ulid.data[13] = b[13]; + ulid.data[14] = b[14]; + ulid.data[15] = b[15]; +} + +/** + * Unmarshal will create a new ULID by unmarshaling the passed byte vector. + * */ +inline ULID UnmarshalBinary(const std::vector<uint8_t>& b) { + ULID ulid; + UnmarshalBinaryFrom(b.data(), ulid); + return ulid; +} + +/** + * CompareULIDs will compare two ULIDs. + * returns: + * -1 if ulid1 is Lexicographically before ulid2 + * 1 if ulid1 is Lexicographically after ulid2 + * 0 if ulid1 is same as ulid2 + * */ +inline int CompareULIDs(const ULID& ulid1, const ULID& ulid2) { + // for (int i = 0 ; i < 16 ; i++) { + // if (ulid1.data[i] != ulid2.data[i]) { + // return (ulid1.data[i] < ulid2.data[i]) * -2 + 1; + // } + // } + + // unrolled loop + + if (ulid1.data[0] != ulid2.data[0]) { + return (ulid1.data[0] < ulid2.data[0]) * -2 + 1; + } + + if (ulid1.data[1] != ulid2.data[1]) { + return (ulid1.data[1] < ulid2.data[1]) * -2 + 1; + } + + if (ulid1.data[2] != ulid2.data[2]) { + return (ulid1.data[2] < ulid2.data[2]) * -2 + 1; + } + + if (ulid1.data[3] != ulid2.data[3]) { + return (ulid1.data[3] < ulid2.data[3]) * -2 + 1; + } + + if (ulid1.data[4] != ulid2.data[4]) { + return (ulid1.data[4] < ulid2.data[4]) * -2 + 1; + } + + if (ulid1.data[5] != ulid2.data[5]) { + return (ulid1.data[5] < ulid2.data[5]) * -2 + 1; + } + + if (ulid1.data[6] != ulid2.data[6]) { + return (ulid1.data[6] < ulid2.data[6]) * -2 + 1; + } + + if (ulid1.data[7] != ulid2.data[7]) { + return (ulid1.data[7] < ulid2.data[7]) * -2 + 1; + } + + if (ulid1.data[8] != ulid2.data[8]) { + return (ulid1.data[8] < ulid2.data[8]) * -2 + 1; + } + + if (ulid1.data[9] != ulid2.data[9]) { + return (ulid1.data[9] < ulid2.data[9]) * -2 + 1; + } + + if (ulid1.data[10] != ulid2.data[10]) { + return (ulid1.data[10] < ulid2.data[10]) * -2 + 1; + } + + if (ulid1.data[11] != ulid2.data[11]) { + return (ulid1.data[11] < ulid2.data[11]) * -2 + 1; + } + + if (ulid1.data[12] != ulid2.data[12]) { + return (ulid1.data[12] < ulid2.data[12]) * -2 + 1; + } + + if (ulid1.data[13] != ulid2.data[13]) { + return (ulid1.data[13] < ulid2.data[13]) * -2 + 1; + } + + if (ulid1.data[14] != ulid2.data[14]) { + return (ulid1.data[14] < ulid2.data[14]) * -2 + 1; + } + + if (ulid1.data[15] != ulid2.data[15]) { + return (ulid1.data[15] < ulid2.data[15]) * -2 + 1; + } + + return 0; +} + +/** + * Time will extract the timestamp used to generate a ULID + * */ +inline time_t Time(const ULID& ulid) { + time_t ans = 0; + + ans |= ulid.data[0]; + + ans <<= 8; + ans |= ulid.data[1]; + + ans <<= 8; + ans |= ulid.data[2]; + + ans <<= 8; + ans |= ulid.data[3]; + + ans <<= 8; + ans |= ulid.data[4]; + + ans <<= 8; + ans |= ulid.data[5]; + + return ans; +} + +}; // namespace ulid + +#endif // ULID_STRUCT_HH diff --git a/src/support/ulid/ulid_wrap.cpp b/src/support/ulid/ulid_wrap.cpp new file mode 100644 index 0000000..0cafe2b --- /dev/null +++ b/src/support/ulid/ulid_wrap.cpp @@ -0,0 +1,21 @@ +#include "ulid_struct.hh" +#include <string.h> +#include <time.h> +#include <pthread.h> +using namespace std; + +#ifdef __cplusplus +extern "C" { +#endif +void ulid_uuid_generate(unsigned char result[16]) +{ + static __thread std::mt19937 generator(time(NULL) * pthread_self()); + ulid::ULID ulid; + ulid::EncodeTimeNow(ulid); + ulid::EncodeEntropyMt19937(generator, ulid); + memcpy(result, ulid.data, 16); +} + +#ifdef __cplusplus +} +#endif diff --git a/src/support/ulid/ulid_wrap.h b/src/support/ulid/ulid_wrap.h new file mode 100644 index 0000000..79dec62 --- /dev/null +++ b/src/support/ulid/ulid_wrap.h @@ -0,0 +1,13 @@ +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif +#include <uuid/uuid.h> + +void ulid_uuid_generate(uuid_t uuid_res); + +#ifdef __cplusplus +} +#endif diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index a3dc3af..8550db8 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -64,4 +64,3 @@ if(MEM_POOL STREQUAL "MIMALLOC") set_property(TARGET libmimalloc-dynamic PROPERTY IMPORTED_LOCATION ${INSTALL_DIR}/lib64/mimalloc-2.1/libmimalloc.so) set_property(TARGET libmimalloc-dynamic PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include/mimalloc-1.8) endif() - |
