summaryrefslogtreecommitdiff
path: root/include/MESA/stream_inc
diff options
context:
space:
mode:
Diffstat (limited to 'include/MESA/stream_inc')
-rw-r--r--include/MESA/stream_inc/gdev_keepalive.h37
-rw-r--r--include/MESA/stream_inc/sapp_inject.h37
-rw-r--r--include/MESA/stream_inc/stream_base.h634
-rw-r--r--include/MESA/stream_inc/stream_bridge.h100
-rw-r--r--include/MESA/stream_inc/stream_control.h342
-rw-r--r--include/MESA/stream_inc/stream_entry.h98
-rw-r--r--include/MESA/stream_inc/stream_inject.h282
-rw-r--r--include/MESA/stream_inc/stream_project.h160
-rw-r--r--include/MESA/stream_inc/stream_proxy.h53
-rw-r--r--include/MESA/stream_inc/stream_rawpkt.h112
-rw-r--r--include/MESA/stream_inc/stream_tunnel.h104
11 files changed, 1959 insertions, 0 deletions
diff --git a/include/MESA/stream_inc/gdev_keepalive.h b/include/MESA/stream_inc/gdev_keepalive.h
new file mode 100644
index 0000000..8211c40
--- /dev/null
+++ b/include/MESA/stream_inc/gdev_keepalive.h
@@ -0,0 +1,37 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "stream_inc/stream_base.h"
+
+
+enum gdev_keepalive_opt_t{
+ GDEV_KEEPALIVE_OPT_SERVICE_CTRL, /* ��������ij��ҵ����Ƿ񱣻� opt_val is struct gdev_keepalive_service_ctrl */
+ GDEV_KEEPALIVE_OPT_GLOBAL_SWITCH, /* ȫ���Ա����, opt_val is int */
+ GDEV_KEEPALIVE_OPT_RCV_PKT_PPS, /* �յ��ı��������/��, opt_val is long */
+ GDEV_KEEPALIVE_OPT_SND_PKT_PPS, /* �յ��ı��������/��, opt_val is long */
+};
+
+struct gdev_keepalive_service_ctrl{
+ int service_num; /* ҵ���, service number */
+ int keepalive_switch; /* 1:����, enable keepalive; 0:������, disable keepalive */
+};
+
+
+int gdev_keepalive_set_opt(const SAPP_TLV_T *tlv_value);
+
+int gdev_keepalive_get_opt(SAPP_TLV_T *tlv_value);
+
+
+/* ��Դ�˿ڻ�ȡ��ǰ������ҵ��� */
+unsigned char vxlan_sport_map_to_service_id(unsigned short sport_host_order);
+
+/* ��vxlan_id��ȡ��ǰ������ҵ��� */
+unsigned char vxlan_id_map_to_service_id(int vxlan_id_host_order);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
diff --git a/include/MESA/stream_inc/sapp_inject.h b/include/MESA/stream_inc/sapp_inject.h
new file mode 100644
index 0000000..cbcaab1
--- /dev/null
+++ b/include/MESA/stream_inc/sapp_inject.h
@@ -0,0 +1,37 @@
+#ifndef _SAPP_INJECT_H_
+#define _SAPP_INJECT_H_ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "stream_base.h"
+
+enum sapp_inject_opt{
+ SIO_DEFAULT = (1<<0), /* ������ֻ���봿����, ��ƽ̨����Э��淶���쵱ǰ��Ĵ�����IPͷ��, ���������, ����������Ƕ�ײ��ͷ�� */
+ SIO_EXCLUDE_THIS_LAYER_HDR = (1<<1), /* ��������, ��ǰ��Ĵ�����IPͷ��Ҳ�ɵ����߹���, ƽ̨���������ǰ��ij��ز�ͷ��, ���������, ����������Ƕ�ײ��ͷ�� */
+};
+
+/*
+ ARGS:
+ stream: ��ǰ���ṹ��ָ��;
+ payload: Ҫ���͵ĸ���ָ��;
+ payload_len: Ҫ���͵ĸ��س���;
+ snd_routedir: Ҫ�������ݵ�route����,
+ ������͵İ��뵱ǰ��ͬ��, snd_routedir = stream->routedir,
+ ������͵İ��뵱ǰ������, snd_routedir = MESA_dir_reverse(stream->routedir).
+
+ return value:
+ <=0 : error.
+ > 0 : ���͵����ݰ�ʵ���ܳ���(payload_len + �ײ��ͷ����);
+*/
+int sapp_inject_pkt(struct streaminfo *stream, enum sapp_inject_opt sio, const void *payload, int payload_len, unsigned char snd_routedir);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/include/MESA/stream_inc/stream_base.h b/include/MESA/stream_inc/stream_base.h
new file mode 100644
index 0000000..afca3e7
--- /dev/null
+++ b/include/MESA/stream_inc/stream_base.h
@@ -0,0 +1,634 @@
+#ifndef _APP_STREAM_BASE_H_
+#define _APP_STREAM_BASE_H_
+
+#define STREAM_BASE_H_VERSION (20210621)
+
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <netinet/ip6.h>
+#include <netinet/tcp.h>
+#include <netinet/udp.h>
+#include <linux/if_ether.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef UINT8
+typedef unsigned char UINT8;
+#endif
+#ifndef UCHAR
+typedef unsigned char UCHAR;
+#endif
+#ifndef UINT16
+typedef unsigned short UINT16;
+#endif
+
+#ifndef UINT32
+typedef unsigned int UINT32;
+#endif
+#ifndef UINT64
+typedef unsigned long long UINT64;
+#endif
+
+/* CHN : ������� */
+/* ENG : stream direction definition*/
+#define DIR_C2S 0x01
+#define DIR_S2C 0x02
+#define DIR_DOUBLE 0x03
+
+/* CHN : ����ײ㴫�䷽����,����ģʽ������ */
+/* ENG : network topology route direction, is valid in serial mode */
+#define DIR_ROUTE_UP 0x00
+#define DIR_ROUTE_DOWN 0x01
+
+/* CHN : ���������Ͷ��� */
+/* ENG : single packet type definition */
+#define PKT_TYPE_NORMAL (0x0) /* normal, common */
+#define PKT_TYPE_IPREBUILD (1<<0) /* ip frag reassembled packet; ip��Ƭ���鱨�� */
+#define PKT_TYPE_TCPUNORDER (1<<1) /* TCP out of order packet; TCP������ */
+#define PKT_TYPE_TCPREORDER (1<<2) /* TCP sequential packet; TCP��������õ����ݰ� */
+#define PKT_TYPE_TCPRETRANS (1<<3) /* TCP retransmit packet; TCP�ش����� */
+#define PKT_TYPE_IP_FRAG (1<<4) /* IP frag packet; IP��Ƭ�� */
+#define PKT_TYPE_IP_FRAG_LAST (1<<5) /* last IP frag packet; ͬ����һ��ԭʼ����IP�������һ��IP��Ƭ�� */
+
+/* CHN : ��ַ���Ͷ���, ��ͨ������ addr_type_to_string() ת���ַ�����ʽ. */
+/* ENG : address type, transform to string mode by call addr_type_to_string(). */
+enum addr_type_t{
+ __ADDR_TYPE_INIT = 0,
+ ADDR_TYPE_IPV4, /* 1, struct stream_tuple4_v4 */
+ ADDR_TYPE_IPV6, /* 2, struct stream_tuple4_v6 */
+ ADDR_TYPE_VLAN, /* 3, 802.1Q */
+ ADDR_TYPE_MAC, /* 4 */
+ ADDR_TYPE_ARP = 5, /* 5 */
+ ADDR_TYPE_GRE, /* 6 */
+ ADDR_TYPE_MPLS, /* 7 */
+ ADDR_TYPE_PPPOE_SES, /* 8 */
+ ADDR_TYPE_TCP, /* 9 */
+ ADDR_TYPE_UDP = 10, /* 10 */
+ ADDR_TYPE_L2TP, /* 11 */
+ __ADDR_TYPE_IP_PAIR_V4, /* 12, ipv4 layer in tunnel mode */
+ __ADDR_TYPE_IP_PAIR_V6, /* 13, ipv6 layer in tunnel mode */
+ ADDR_TYPE_PPP, /* 14 */
+ ADDR_TYPE_PPTP, /* 15 */
+ ADDR_TYPE_MAC_IN_MAC, /* 16 */
+ ADDR_TYPE_GPRS_TUNNEL, /* 17 */
+ ADDR_TYPE_VXLAN, /* 18 */
+ __ADDR_TYPE_MAX, /* 19 */
+};
+
+#define TCP_TAKEOVER_STATE_FLAG_OFF 0
+#define TCP_TAKEOVER_STATE_FLAG_ON 1
+
+
+/* CHN : Ӧ�ò㿴��������״̬���� */
+/* ENG : stream state for protocol or business plug*/
+#define OP_STATE_PENDING 0
+#define _OP_STATE_OBSOLETE 1 /* is obsolete */
+#define OP_STATE_CLOSE 2
+#define OP_STATE_DATA 3
+
+/* CHN : Ӧ�ò㷵�ؽ������ */
+/* ENG : return value of plug */
+#define APP_STATE_GIVEME 0x00
+#define APP_STATE_DROPME 0x01
+#define APP_STATE_FAWPKT 0x00
+#define APP_STATE_DROPPKT 0x10
+
+
+#define APP_STATE_KILL_FOLLOW 0x40 /* ǿ��CLOSE��ǰ������������в�� */
+#define APP_STATE_KILL_OTHER 0x80 /* ǿ��CLOSE����ǰ���������в�� */
+
+
+/* CHN : �������Ͷ��� */
+/* ENG : stream type */
+enum stream_type_t{
+ STREAM_TYPE_NON = 0, /* No stream concept indeed, such as vlan, IP, etc.; �����ĸ���, ��VLAN, IP��� */
+ STREAM_TYPE_TCP,
+ STREAM_TYPE_UDP, /* there is no stream of UDP in RFC, but in MESA platform, we build a UDP stream with same tuple4 packet */
+ STREAM_TYPE_VLAN,
+ STREAM_TYPE_SOCKS4,
+ STREAM_TYPE_SOCKS5,
+ STREAM_TYPE_HTTP_PROXY,
+ STREAM_TYPE_PPPOE,
+ STREAM_TYPE_L2TP,
+ STREAM_TYPE_OPENVPN,
+ STREAM_TYPE_PPTP,
+ STREAM_TYPE_ISAKMP,
+};
+
+/*
+ CHN: ���ĵײ������������,
+ ��ͬ��stream_type_t, ���統ǰ��ΪSTREAM_TYPE_TCP, ���ײ��������Ϳ�����STREAM_TUNNLE_PPTP.
+ ��Ϊ���������Ƕ��ֲ�ͬ����Ƕ�����, ֻ��¼��ײ�(��MAC�������)��������.
+*/
+enum stream_carry_tunnel_t{
+ STREAM_TUNNLE_NON = 0, /* default is 0, not tunnel; Ĭ��Ϊ0, ������; */
+ STREAM_TUNNLE_6OVER4 = 1 << 0,
+ STREAM_TUNNLE_4OVER6 = 1 << 1,
+ STREAM_TUNNLE_GRE = 1 << 2,
+ STREAM_TUNNLE_IP_IN_IP = 1 << 3,
+ STREAM_TUNNLE_PPTP = 1 << 4,
+ STREAM_TUNNLE_L2TP = 1 << 5,
+ STREAM_TUNNLE_TEREDO = 1 << 6,
+ STREAM_TUNNEL_GPRS_TUNNEL = 1 << 7,
+ STREAM_TUNNEL_MULTI_MAC = 1 << 8, /* is obsoulte */
+};
+
+typedef struct raw_ipfrag_list{
+ void *frag_packet; /* ��ip��ͷ, �ӵײ�������ȡ��ԭʼ��ͷ */
+ int pkt_len;
+ int type; /* IPv4 or IPv6 */
+ struct raw_ipfrag_list *next;
+}raw_ipfrag_list_t;
+
+
+#ifndef STRUCT_TUPLE4_DEFINED
+#define STRUCT_TUPLE4_DEFINED (1)
+/* compat for start, papp; ����start, papp */
+struct tuple4 {
+ u_int saddr;
+ u_int daddr;
+ u_short source;
+ u_short dest;
+};
+#endif
+
+struct tuple6
+{
+ UCHAR saddr[16] ;
+ UCHAR daddr[16] ;
+ UINT16 source;
+ UINT16 dest;
+};
+
+/* network-order */
+struct stream_tuple4_v4{
+ UINT32 saddr; /* network order */
+ UINT32 daddr; /* network order */
+ UINT16 source; /* network order */
+ UINT16 dest; /* network order */
+};
+
+
+#ifndef IPV6_ADDR_LEN
+#define IPV6_ADDR_LEN (sizeof(struct in6_addr))
+#endif
+
+struct stream_tuple4_v6
+{
+ UCHAR saddr[IPV6_ADDR_LEN] ;
+ UCHAR daddr[IPV6_ADDR_LEN] ;
+ UINT16 source; /* network order */
+ UINT16 dest; /* network order */
+};
+
+
+#define GRE_TAG_LEN (4)
+struct layer_addr_gre
+{
+ UINT16 call_id; /* network order */
+};
+
+
+#define VLAN_ID_MASK (0x0FFF)
+#define VLAN_TAG_LEN (4)
+#define MAX_VLAN_ADDR_LAYER (2)
+
+
+struct single_layer_vlan_addr{ /* refer to https://en.wikipedia.org/wiki/IEEE_802.1Q */
+ unsigned short TPID; /* Tag protocol identifier, network order */
+ unsigned char PCP; /* Priority code point */
+ unsigned char DEI; /* Drop eligible indicator */
+ unsigned short VID; /* VLAN identifier, network order */
+};
+
+
+struct layer_addr_vlan
+{
+ struct single_layer_vlan_addr c2s_addr_array[MAX_VLAN_ADDR_LAYER];
+ struct single_layer_vlan_addr s2c_addr_array[MAX_VLAN_ADDR_LAYER];
+ UCHAR c2s_layer_num;
+ UCHAR s2c_layer_num;
+};
+
+
+struct layer_addr_pppoe_session
+{
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ unsigned int ver:4;
+ unsigned int type:4;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+ unsigned int type:4;
+ unsigned int ver:4;
+#endif
+ unsigned char code;
+ unsigned short session_id;
+};
+
+#ifndef MAC_ADDR_LEN
+#define MAC_ADDR_LEN (6)
+#endif
+
+struct layer_addr_mac
+{
+ /*
+ C2S��S2C�������Բ�ͬ����·���豸, �ᵼ�����������mac��ַȫ��һ��, ����ע��ʱ�����ô�ͳ��ʽ, ���򵥵ĵߵ�src��dst,
+ �޸Ķ�������, mirrorģʽ��, ���Ǵ洢��src_addr��,
+ API��ͬ��, ABI������ǰ���ݵ�, �ṹ���ڴ�ֲ���֮ǰ��һ��.
+ */
+ struct ethhdr src_addr;
+ struct ethhdr dst_addr;
+
+ //UCHAR dst_mac[MAC_ADDR_LEN]; /* network order */
+ //UCHAR src_mac[MAC_ADDR_LEN]; /* network order */
+};
+
+struct layer_addr_ipv4
+{
+ UINT32 saddr; /* network order */
+ UINT32 daddr; /* network order */
+ /* 2014-04-21 lijia add,
+ Ϊ�˽�Լ�ڴ�ռ䡢�ʹ���Ч��, ��ǿ�ư�Э���δ���,
+ IP���TCP����Ϊһ����,
+ �����������IP, �˿���ϢΪ0;
+ */
+ UINT16 source; /* network order */
+ UINT16 dest; /* network order */
+};
+
+struct layer_addr_ipv6
+{
+ UCHAR saddr[IPV6_ADDR_LEN] ; /* network order */
+ UCHAR daddr[IPV6_ADDR_LEN] ; /* network order */
+ /* 2014-04-21 lijia add,
+ Ϊ�˽�Լ�ڴ�ռ䡢�ʹ���Ч��, ��ǿ�ư�Э���δ���,
+ IP���TCP����Ϊһ����,
+ �����������IP, �˿���ϢΪ0;
+ */
+ UINT16 source;/* network order */
+ UINT16 dest;/* network order */
+};
+
+struct layer_addr_tcp
+{
+ UINT16 source; /* network order */
+ UINT16 dest; /* network order */
+};
+
+struct layer_addr_udp
+{
+ UINT16 source; /* network order */
+ UINT16 dest; /* network order */
+};
+
+
+struct layer_ppp_hdr{
+ unsigned char address;
+ unsigned char control;
+ unsigned short protocol; /* network order */
+}__attribute__((packed));
+
+/* һ�������, address,control���ǹ̶������,����0xFF,0x03, ppp hdr�ǿ���ѹ���Խ�Լ����,ֻ����һ���ֽڵ�protocol�ֶ� */
+struct layer_compress_ppp_hdr{
+ unsigned char protocol;
+};
+
+
+struct layer_addr_l2tp_v2_t{
+ UINT16 tunnelid_C2S; /* network order, �Դ���㴴�����ķ���Ϊ׼ */
+ UINT16 tunnelid_S2C; /* network order, �Դ���㴴�����ķ���Ϊ׼ */
+ UINT16 sessionid_C2S; /* network order, �Դ���㴴�����ķ���Ϊ׼ */
+ UINT16 sessionid_S2C; /* network order, �Դ���㴴�����ķ���Ϊ׼ */
+ unsigned char seq_present_C2S;
+ unsigned char seq_present_S2C;
+ unsigned char ppp_hdr_compress_enable;
+ union{
+ struct layer_ppp_hdr ppp_hdr;
+ struct layer_compress_ppp_hdr compress_ppp_hdr;
+ };
+};
+
+struct layer_addr_l2tp_v3_t{
+ UINT32 sessionlid; /* network order */
+};
+
+struct layer_addr_l2tp
+{
+ UCHAR version; /* v2 or v3 */
+ union
+ {
+ struct layer_addr_l2tp_v2_t l2tp_addr_v2;
+ struct layer_addr_l2tp_v3_t l2tp_addr_v3;
+ }l2tpun;
+};
+
+#define MAX_MPLS_ADDR_LAYER 4
+
+struct single_layer_mpls_addr{ /* refer to RFC3032 */
+ unsigned int label; /* network order */
+ unsigned char experimental;
+ unsigned char bottom;
+ unsigned char ttl;
+};
+
+/*
+ MPLS�п����Ƕ��Ƕ��, sapp�Ѷ��ϲ�����, Ŀǰ���֧��4��, ���������⵽������, 0��ʾ�����, 3��ʾ���ڲ�
+ ����һ���ڲ�TCP/UDP����˵, �ײ�MPLS��������ĵ�ַ���ܲ�һ��, �ֱ��Ϊcs2_addr, s2c_addr.
+*/
+struct layer_addr_mpls
+{
+ struct single_layer_mpls_addr c2s_addr_array[MAX_MPLS_ADDR_LAYER];
+ struct single_layer_mpls_addr s2c_addr_array[MAX_MPLS_ADDR_LAYER];
+ char c2s_layer_num; /* ʵ��mpls���� */
+ char s2c_layer_num; /* ʵ��mpls���� */
+ char c2s_has_ctrl_word;
+ char s2c_has_ctrl_word;
+ unsigned int c2s_mpls_ctrl_word; /* refer to RFC4623 */
+ unsigned int s2c_mpls_ctrl_word; /* refer to RFC4623 */
+};
+
+
+struct layer_addr_pptp
+{
+ UINT16 C2S_call_id; /* C2S�Դ����Э�鷽��Ϊ׼, TCP SYNΪC2S, UDPԴ�˿ڴ��ΪC2S, callid, network order */
+ UINT16 S2C_call_id; /* S2Ck�Դ����Э�鷽��Ϊ׼, TCP SYN/ACKΪS2C, UDPĿ�Ķ˿ڴ��ΪS2C, callid, network order */
+};
+
+struct layer_addr_gtp
+{
+ unsigned int teid_c2s; /* network order */
+ unsigned int teid_s2c; /* network order */
+}__attribute__ ((aligned (1)));
+
+#define MAC_IN_MAC_HDR_LEN (sizeof(struct mesa_ethernet_hdr) + sizeof(struct mesa_ethernet_hdr))
+struct layer_addr_mac_in_mac
+{
+ UCHAR outer_dst_mac[MAC_ADDR_LEN]; /* �����mac��ַ, network order */
+ UCHAR outer_src_mac[MAC_ADDR_LEN]; /* �����mac��ַ, network order */
+ UCHAR inner_dst_mac[MAC_ADDR_LEN]; /* �ڲ�mac��ַ, network order */
+ UCHAR inner_src_mac[MAC_ADDR_LEN]; /* �ڲ�mac��ַ, network order */
+};
+
+struct layer_addr_vxlan
+{
+ UINT16 vlan_id; /* network order */
+ UCHAR dir;
+ UCHAR link_id;
+ UCHAR link_type;
+};
+
+
+struct layer_addr
+{
+ UCHAR addrtype; /* definition in enum addr_type_t */
+ UCHAR addrlen;
+ UCHAR pkttype; /* packet special features, definition in MACRO PKT_TYPE_xxx */
+ UCHAR pktipfragtype; /* ip frag packetfeatures, definition in MACRO PKT_TYPE_xxx */
+
+ UCHAR __pad[4]; /* pad for alignment */
+ union
+ {
+ struct stream_tuple4_v4 *tuple4_v4;
+ struct stream_tuple4_v6 *tuple4_v6;
+ struct layer_addr_ipv4 *ipv4;
+ struct layer_addr_ipv6 *ipv6;
+ struct layer_addr_vlan *vlan;
+ struct layer_addr_mac *mac;
+ struct layer_addr_gre *gre;
+ struct layer_addr_tcp *tcp;
+ struct layer_addr_udp *udp;
+ struct layer_addr_pppoe_session *pppoe_ses;
+ struct layer_addr_l2tp *l2tp;
+ struct layer_addr_pptp *pptp;
+ struct layer_addr_mac_in_mac *mimac;
+ struct layer_addr_gtp *gtp;
+ struct layer_addr_mpls *mpls;
+ struct layer_addr_vxlan *vxlan;
+ void *paddr;
+ };
+
+};
+
+/* CHN : �����˽ṹ���ں�papp����, ����ָ��ʱ, ����struct layer_addrǿת */
+/* ENG : compat for papp, can be transform to struct layer_addr pointer */
+struct ipaddr
+{
+ UCHAR addrtype; /* definition in enum addr_type_t */
+ UCHAR addrlen;
+ UCHAR pkttype; /* packet special features, definition in MACRO PKT_TYPE_xxx */
+ UCHAR pktipfragtype; /* ip frag packetfeatures, definition in MACRO PKT_TYPE_xxx */
+ UCHAR __pad[4]; /* pad for alignment */
+ union
+ {
+ struct stream_tuple4_v4 *v4;
+ struct stream_tuple4_v6 *v6;
+ void *paddr;
+ };
+
+};
+
+struct tcpdetail
+{
+ void *pdata;
+ UINT32 datalen;
+ UINT32 lostlen; /* lost data len, not accumulated, current procedure */
+ UINT32 serverpktnum; /* C2S, this value indicate TCP-ALL packet, include syn, ack, rst, if want get tcp data status, use stream_project.h : struct tcp_flow_stat */
+ UINT32 clientpktnum; /* S2C, this value indicate TCP-ALL packet, include syn, ack, rst, if want get tcp data status, use stream_project.h : struct tcp_flow_stat */
+ UINT32 serverbytes; /* C2S, this value indicate TCP-ALL packet, include syn, ack, rst, if want get tcp data status, use stream_project.h : struct tcp_flow_stat */
+ UINT32 clientbytes; /* S2C, this value indicate TCP-ALL packet, include syn, ack, rst, if want get tcp data status, use stream_project.h : struct tcp_flow_stat */
+ UINT64 createtime;
+ UINT64 lastmtime;
+};
+
+struct udpdetail
+{
+ void *pdata;
+ UINT32 datalen;
+ UINT32 pad;
+ UINT32 serverpktnum; /* C2S, you should better use stream_project.h : struct udp_flow_stat */
+ UINT32 clientpktnum; /* S2C, you should better use stream_project.h : struct udp_flow_stat */
+ UINT32 serverbytes; /* C2S, you should better use stream_project.h : struct udp_flow_stat */
+ UINT32 clientbytes; /* S2C, you should better use stream_project.h : struct udp_flow_stat */
+ UINT64 createtime;
+ UINT64 lastmtime;
+};
+
+struct streaminfo
+{
+ struct layer_addr addr;
+ struct streaminfo *pfather; /* this stream's carry layer stream; �ϲ����ṹ�� */
+ UCHAR type; /* stream type, definition in enum stream_type_t */
+ UCHAR threadnum;
+ UCHAR dir; /* valid in all stream life, current stream direction state, 0x01:c-->s; 0x02:s-->c; 0x03 c<-->s; */
+ UCHAR curdir; /* valid in current procedure, current packet direction, 0x01:c-->s; 0x02:s-->c */
+ UCHAR opstate; /* stream state, definition in MACRO OP_STATE_xxx */
+ UCHAR pktstate; /* for TCPALL plug, stream state, definition in MACRO OP_STATE_xxx */
+ UCHAR routedir; /* network topology route direction, is valid in serial mode */
+ UCHAR stream_state; /* stream management state, for example, in TCP stream, maybe SYN, DATA, NOUSE */
+ UINT32 hash_index; /* stream hash index, maybe reduplicate with other stream when hash algorithm collide */
+ UINT32 stream_index; /* stream global index per thread */
+ union
+ {
+ struct tcpdetail *ptcpdetail;
+ struct udpdetail *pudpdetail;
+ void *pdetail;
+ };
+ };
+
+
+typedef struct {
+ unsigned int type;
+ unsigned int length;
+ union{
+ char char_value;
+ short short_value;
+ int int_value;
+ long long_value;
+ char array_value[8];
+ void *ptr_value; /* more than 8bytes data, or complex struct. */
+ };
+}SAPP_TLV_T;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* CHN : �ڴ������غ���, ����ƽ̨�IJ������ʹ�ô��ຯ��������ͷ��ڴ� */
+/* ENG : memory management function, plugs must call these functions instead of malloc, free in <stdlib.h> */
+void *dictator_malloc(int thread_seq,size_t size);
+void dictator_free(int thread_seq,void *pbuf);
+void *dictator_realloc(int thread_seq, void* pbuf, size_t size);
+
+/* CHN : ��ȡ��ǰϵͳ���еIJ��������߳����� */
+/* ENG : get current total thread of platfomr */
+int get_thread_count(void);
+
+/* CHN : ����enum addr_type_tַ����ת���ɿɴ�ӡ���ַ�����ʽ */
+/* ENG : transform binary addr_type_t to string mode */
+const char *addr_type_to_string(enum addr_type_t type);
+
+/*
+ ENG : transform tuple4 to string mode, must used in packet process thread context;
+ CHN : ��layer_addr��ַת�����ַ�����ʽ, �������ڰ������߳�.
+*/
+const char *printaddr (const struct layer_addr *paddrinfo, int threadindex);
+
+/*
+ ENG : a reentrant version of printaddr, thread safe;
+ CHN : printaddr�Ŀ�����汾, ���̰߳�ȫ��.
+*/
+const char *printaddr_r(const struct layer_addr *paddrinfo, char *out_buf, int out_buf_len);
+
+
+/*
+ ENG : transform layer address to string mode, must used in packet process thread context,
+ the return value is read-only, user can't free it;
+ CHN : ��layer_addr��ַת�����ַ�����ʽ, �������ڰ������߳�, ���ص�ָ��Ϊֻ��, ʹ���߲���free.
+*/
+const char *layer_addr_ntop(const struct streaminfo *pstream);
+
+/*
+ ENG : a reentrant version of layer_addr_ntop, thread safe, return a pointer to the destination string 'out_buf';
+ CHN : layer_addr_ntop_r�Ŀ�����汾, ���̰߳�ȫ��, ���ص�ָ��ִ��ʹ�����ṩ��out_buf, ���ڴ�����֯.
+*/
+char *layer_addr_ntop_r(const struct streaminfo *pstream, char *out_buf, int out_buf_len);
+
+/*
+ ENG : transform layer type to abbr string mode, is reentrant, the return value is read-only, user can't free it;.
+ CHN : ��layer_addr��ַ����ת������д�ַ�����ʽ, �������̰߳�ȫ, ���ص�ָ��Ϊֻ��, ʹ���߲���free..
+*/
+const char *layer_addr_prefix_ntop(const struct streaminfo *pstream);
+
+
+/*
+ ENG : duplicate a same layer_addr struct, memory obtained with malloc(3);
+ CHN : ����һ����ȫ��ͬ��layer_addr�ṹ��, �ڴ�ͨ��malloc(3)��ȡ.
+*/
+struct layer_addr * layer_addr_dup(const struct layer_addr *paddrinfo);
+
+/*
+ ENG: used to free all memory of paddrinfo;
+ CHN: �����ͷ�paddrinfo�ڴ�.
+*/
+void layer_addr_free(struct layer_addr *paddrinfo);
+
+
+/*
+ ENG : duplicate a same streaminfo list, memory obtained with malloc(3);
+ CHN : ����һ����ȫ��ͬ��streaminfo�ṹ�弰�����ṹ, �ڴ�ͨ��malloc(3)��ȡ.
+*/
+struct streaminfo *streaminfo_dup(const struct streaminfo *stream);
+
+/*
+ ENG: used to free all memory of streaminfo;
+ CHN: �����ͷŽṹ�弰�����ṹ���ڴ�.
+*/
+void streaminfo_free(struct streaminfo *stream);
+
+
+/*
+ addr list transform function, like inet_ntop(), inet_pton(),
+ use '<' as delimitation between layer,
+ if direction is double, for ip, port, use '-' as delimitation between source and destination,
+
+ for example:
+ "T4T:6005-1673<IP4:61.147.112.53-11.215.62.23<MAC:0000ea60040d-0200000003b6"
+
+ args:
+ pstream : stream info;
+ dst : buf to store result;
+ size : dst buf's size;
+ addr_list_str: addr list string;
+ thread_index : thread index;
+
+ ����ֵ:
+ >0:ת����Ľ��ʵ��ռ���ڴ泤��, stream_addr_list_ntop()�������ַ���ĩβ��'\0';
+ -1:dst����ռ䳤�Ȳ���;
+ -2:��ʽ����;
+ -3:��������;
+*/
+int stream_addr_list_ntop(const struct streaminfo *pstream, char *dst, int size);
+int stream_addr_list_pton(const char *addr_list_str, void *dst, int size, int thread_index);
+
+/*
+ TCP,UDP��ģʽ��, ��ȡ��ǰIP����ԭʼ��Ƭ��.
+*/
+const raw_ipfrag_list_t *get_raw_frag_list(const struct streaminfo *stream);
+
+/*
+ IP���ģʽ��, ��ȡ��ǰIP����ԭʼ��Ƭ��.
+*/
+const raw_ipfrag_list_t *ip_plug_get_raw_ipfrag_list(int thread_num, enum addr_type_t addr_type);
+
+
+/*
+ ��Ϊ������Ƕ��Э���ԭ��, ����һ������Ԫ��, ʵ���п��ܲ�ѯ�����streaminfo,
+ ��������������:
+ (1) tuple4->gtp->ip->udp->ethernet;
+ (2) tuple4->l2tp->ip->udp->ethernet;
+ ��������ڲ�ʹ��˽�е�ַ, ��һЩ���˴��ɵ������, ��1����2���ڲ�tuple4������һ����, ��sapp�ᴴ��������ͬ��streaminfo.
+
+ �������:
+ thread_index: �߳�id;
+ tuple4v4 or tuple4v6: ��Ԫ���ַ, Դ��Ŀ�ĵ�ַ˳����Ҫ��, C2S, S2c�������;
+ streamtype: ֻ֧����������, STREAM_TYPE_TCP or STREAM_TYPE_UDP;
+ array_max_num: ����streaminfo_array�����Ԫ�ظ���.
+
+ �������:
+ streaminfo_array: ��ѯ���ķ���������Ԫ���ַ��streaminfo�ṹ��ָ��.
+
+ ����ֵ:
+ -1: error;
+ 0: û�ж�Ӧ��streaminfo�ṹ;
+ >0: ʵ���ҵ�streaminfo�ṹ������;
+*/
+int find_streaminfo_by_addrv4(int thread_index, const struct stream_tuple4_v4 *tuplev4, enum stream_type_t streamtype, struct streaminfo *streaminfo_array[], int array_max_num);
+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);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/include/MESA/stream_inc/stream_bridge.h b/include/MESA/stream_inc/stream_bridge.h
new file mode 100644
index 0000000..3164854
--- /dev/null
+++ b/include/MESA/stream_inc/stream_bridge.h
@@ -0,0 +1,100 @@
+#ifndef _SAPP_STREAM_BRIDGE_H_
+#define _SAPP_STREAM_BRIDGE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <errno.h>
+
+
+/***************************************** stream bridge API *************************************************
+
+ stream_bridge_xxx接口用于在不同插件之间, 创建一个通道, 支持同步和异步两种方式互相通信, 支持多对多的关系.
+
+ 同步模式采用callback注册方式, 避免直接使用extern声明函数, 动态、灵活、可扩展.
+ 异步模式是在streaminfo中保留一份数据, 功能同之前的project_req_xxx系列接口.
+
+ 假设插件plug A,X,Y,Z都注册同一个bridge name:"bridge_demo", bridge_id=1,
+
+ plug A使用异步模式在streaminfo, bridge=1的空间存储了一份数据, receiver X,Y,Z可以在streaminfo生存周期内取数据.
+ -------------------
+ | streaminfo | plug X
+ |-----------------| /
+ plug A-->|bridge1 -> data1 |/--plug Y
+ |-----------------|\
+ |bridge2 -> data2 | \ plug Z
+ |-----------------|
+ |bridge3 -> data3 |
+ -------------------
+
+
+ plugA发送一条同步消息, receiver X,Y,Z都可以依次收到.
+
+ -------------------- plug X
+ | /
+ plug A ->| bridge_id = 1 /--plug Y
+ | \
+ | \ plug Z
+ --------------------
+
+*******************************************************************************************************************/
+
+
+/*
+ bridge_name: 全局唯一, 与之前的project使用不同的命名空间, 可以重名,
+ 但是bridge_id与project_req_id不能通用!!!
+
+ rw_mode类似fopen函数的参数, 只支持两个模式:
+ "r": 只读,bridge_name不存在则返回错误;
+ "w": bridge_name不存在则创建一个新的bridge,
+ 注意, 如果其他插件已经创建了同名bridge, 再次用"w"模式打开, 不能像fopen以截断模式重新打开一个文件, 其实bridge_id是一样的!
+ 建议先用"r"模式验证是否有无同名bridge;
+
+ 返回值是bridge_id,
+ >=0 : success
+ <0 : error
+*/
+int stream_bridge_build(const char *bridge_name, const char *rw_mode);
+
+
+typedef void stream_bridge_free_cb_t(const struct streaminfo *stream, int bridge_id, void *data);
+typedef int stream_bridge_sync_cb_t(const struct streaminfo *stream, int bridge_id, void *data);
+
+
+/*
+ 注意: free函数最多只能有一个, 后面会覆盖前面的函数指针, 多次重复注册只保留最后一个!
+*/
+int stream_bridge_register_data_free_cb(int bridge_id, stream_bridge_free_cb_t *free_cb_fun);
+
+/* sync回调函数可以是多个, 调用stream_bridge_sync_data_put()时, 会调用所有注册的callback函数 */
+int stream_bridge_register_data_sync_cb(int bridge_id, stream_bridge_sync_cb_t *sync_cb_fun);
+
+/*
+ 返回值:
+ 0: 没有stream_bridge_sync_cb_t函数;
+ -1: error
+ N: 成功调用stream_bridge_sync_cb_t函数的数量;
+*/
+int stream_bridge_sync_data_put(const struct streaminfo *stream, int bridge_id, void *data);
+
+/* 等同于之前的project_req_add_xxx, 注意如果data是malloc的内存, 要注册stream_bridge_free_cb_t, streaminfo在close时会自动free */
+int stream_bridge_async_data_put(const struct streaminfo *stream, int bridge_id, void *data);
+
+/*
+ 返回值:
+ 非NULL: 插件曾经调用stream_bridge_async_data_put()存储的data值.
+ NULL : 此时会产生一种歧义, 如果stream_bridge_async_data_put()就是存了一个空指针, 或者利用C的特性, 存了一个整数0,
+ 如何区别是错误还是原始数据就是0?
+
+ 如果返回值是NULL的情况下, 插件要再判断一下errno, errno == ENODATA (61), 说明确实没有插件曾经存储过数据, 是个错误.
+*/
+void *stream_bridge_async_data_get(const struct streaminfo *stream, int bridge_id); /* 等同于之前的project_get_xxx */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/include/MESA/stream_inc/stream_control.h b/include/MESA/stream_inc/stream_control.h
new file mode 100644
index 0000000..75e3bb6
--- /dev/null
+++ b/include/MESA/stream_inc/stream_control.h
@@ -0,0 +1,342 @@
+#ifndef _APP_STREAM_CONTROL_H_
+#define _APP_STREAM_CONTROL_H_
+
+#ifdef __cplusplus
+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_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 */
+};
+
+
+/*
+ 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;
+};
+
+#define MAX_TCP_OPT_LEN (38) /* TCPͷ�������Ϊ60�ֽ�, ȥ����׼ͷ��ʣ��ѡ����40�ֽ�, ѡ�����ݲ����38�ֽ� */
+#define MAX_TCP_OPT_NUM (20) /* ����TCP�����ѡ������ */
+
+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)));
+
+
+/* 2018-10-24 lijia add, for pangu ��Ŀmac_in_mac����.
+ ������, sappƽ̨��Ӧ�ù��ĺ�ҵ��������صĶ���, ����mac���ĸ��ֶ���link_id, �ĸ���dev_id,
+ ���������̫�ײ���, ƽ̨����GDEV����RST��ҲҪ�����Щֵ, ����ƽ̨����!!
+*/
+/* Ϊ�˷���ҵ������ȡmac_in_mac��ַ��ľ�����Ϣ, ����ʹ��ԭʼ��bitλ��, ת���ɱ�����ʽ */
+struct vxlan_info{
+ unsigned char encap_type; /* ԭʼ�����װ��ʽ */
+ unsigned char entrance_id; /* �豸���ڳ����ID */
+ unsigned char dev_id; /* �豸ID */
+ unsigned char link_id; /* ��·ID */
+ unsigned char link_dir; /* ��·����, ָ��ǰ��Ԫ���IP������ʱ�Ĵ��䷽��, ����TCP, SYN���Ĵ��䷽��; ����UDP, �˿ڴ�IP�Ĵ��䷽�� */
+ unsigned char inner_smac[18]; /* �ڲ���ʵSMAC, string����, ��: "11:22:33:44:55:66" */
+ unsigned char inner_dmac[18]; /* �ڲ���ʵDMAC, string����, ��: "11:22:33:44:55:66" */
+ unsigned char inner_smac_hex[6]; /* �ڲ���ʵSMAC, ԭʼ���������� */
+ unsigned char inner_dmac_hex[6]; /* �ڲ���ʵDMAC, ԭʼ���������� */
+};
+
+
+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 */
+};
+
+
+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{
+ DEPOLYMENT_MODE_MIRROR = 1,
+ DEPOLYMENT_MODE_TRANSPARENT = 2,
+ DEPOLYMENT_MODE_INLINE = 3,
+};
+
+
+
+/*
+ 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);
+
+
+/*
+ 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:
+ �ڱ���ģʽ��, ����������route_dir�ľ���ֵ, ֻ��Ҫ����ͬ��ͷ��򼴿�,
+ ��������������Ҫ��ȷ����route_dir��0����1, �������������ģʽ��ͬ, ������ʱ��仯,
+ �������ô˽ӿ�, ���ֻ�贫����������ķ���human_dir, ���ص�ǰ��·��link route dir,
+ ע���״β���ʱ, 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��1, ͨ������stream->routedir;
+
+ ����ֵ:
+ 'E' or 'e': ��ʾ���ݰ����䷽���Ǵ�Internal to External.
+ 'I' or 'i': ��ʾ���ݰ����䷽���Ǵ�External to Internal.
+ 'x': ��������;
+*/
+int MESA_dir_link_to_human(int link_route_dir);
+
+
+
+/****************************************************************************************
+ CHN : ��Ϊ��ʷ��������,���ຯ��������Ϊ������,��ʹ���½ӿ�:MESA_set_stream_opt().
+ ENG : 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, UCHAR 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/include/MESA/stream_inc/stream_entry.h b/include/MESA/stream_inc/stream_entry.h
new file mode 100644
index 0000000..9fda956
--- /dev/null
+++ b/include/MESA/stream_inc/stream_entry.h
@@ -0,0 +1,98 @@
+#ifndef _APP_STREAM_ENTRY_H_
+#define _APP_STREAM_ENTRY_H_
+
+#define STREAM_ENTRY_H_VERSION (20190818)
+
+/*
+ CHN : ҵ�����ý�����ʱsession_state״̬;
+*/
+#define SESSION_STATE_PENDING 0x01
+#define SESSION_STATE_DATA 0x02
+#define SESSION_STATE_CLOSE 0x04
+
+//���������ҵ���ʱ�ķ���ֵ��
+#define PROT_STATE_GIVEME 0x01
+#define PROT_STATE_DROPME 0x02
+#define PROT_STATE_DROPPKT 0x04
+
+//������������ҵ�����ʱ�������
+typedef struct _plugin_session_info
+{
+ unsigned short plugid; //plugid��ƽ̨����
+ char session_state; //�Ự״̬��PENDING,DATA,CLOSE
+ char _pad_; //����
+ int buflen; //��ǰ�ֶγ���
+ long long prot_flag; //��ǰ�ֶε�flagֵ
+ void *buf; //��ǰ�ֶ�
+ void* app_info; //��������������Ϣ
+}stSessionInfo;
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef char (*STREAM_CB_FUN_T)(const struct streaminfo *pstream,void **pme, int thread_seq,const void *ip_hdr);
+typedef char (*IPv4_CB_FUN_T)(const struct streaminfo *pstream,unsigned char routedir,int thread_seq, const void *ipv4_hdr);
+typedef char (*IPv6_CB_FUN_T)(const struct streaminfo *pstream,unsigned char routedir,int thread_seq, const void *ipv6_hdr);
+
+
+typedef char (*SAPP_PKT_CB_FUN_T)(const struct streaminfo *pstream, const void *this_hdr, const void *raw_pkt);
+typedef char (*SAPP_STREAM_FUN_T)(const struct streaminfo *pstream, const void *this_hdr, const void *raw_pkt, void **pme);
+
+
+/*����������
+ a_*, pstream: ������������Ϣ;
+ raw_pkt: ԭʼ��ָ��,��ȡ�����Ϣʹ��get_opt_from_rawpkt()�ӿ�;
+ pme: ˽������ָ��;
+ thread_seq���߳����;
+
+��������ֵ������Ϊ�����ĸ�ֵ������
+
+ APP_STATE_GIVEME�������򱾺����Ͱ���
+ APP_STATE_DROPME�������򱾺����Ͱ���
+ APP_STATE_FAWPKT����ע�����ݰ�
+ APP_STATE_DROPPKT������ע�����ݰ�
+*/
+char IPv4_ENTRY_EXAMPLE(const struct streaminfo *pstream,unsigned char routedir,int thread_seq, const void *ipv4_hdr);
+char IPv6_ENTRY_EXAMPLE(const struct streaminfo *pstream,unsigned char routedir,int thread_seq,const void *ipv6_hdr);
+char TCP_ENTRY_EXAMPLE(const struct streaminfo *a_tcp, void **pme, int thread_seq,const void *ip_hdr);
+char UDP_ENTRY_EXAMPLE(const struct streaminfo *a_udp, void **pme, int thread_seq,const void *ip_hdr);
+
+char SAPP_PKT_EXAMPLE(const struct streaminfo *pstream, const void *this_hdr, const void *raw_pkt);
+char SAPP_STREAM_EXAMPLE(const struct streaminfo *pstream, const void *this_hdr, const void *raw_pkt, void **pme);
+
+#define POLLING_STATE_WORK 0x80
+#define POLLING_STATE_IDLE 0x40
+
+/*
+ ÿ��һ��ʱ��, ƽ̨����õ�ǰ�ӿ�, �����������Ƿ������ݰ�.
+ stream, pme, a_packet�̶�����NULL, thread_seq���հ��̵߳����.
+
+ ����ֵ:
+ POLLING_STATE_WORK: �˴λص�����������������������;
+ POLLING_STATE_IDLE: �˴λص����ʲô��û��, ����������û����, ���������ģʽ�հ�, ��ʵ��û���յ���;
+*/
+char POLLING_ENTRY(struct streaminfo *stream, void **pme, int thread_seq,void *a_packet);
+
+
+/*
+ CHN : ҵ���ص��ӿ� ;
+ ENG : business plug API ;
+*/
+
+char PROT_PROCESS(stSessionInfo* session_info, void **pme, int thread_seq,struct streaminfo *a_stream,const void *a_packet);
+
+int libsapp_setup_env(int argc, char *argv[]);
+void libsapp_destroy_env(void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
+
diff --git a/include/MESA/stream_inc/stream_inject.h b/include/MESA/stream_inc/stream_inject.h
new file mode 100644
index 0000000..68259f0
--- /dev/null
+++ b/include/MESA/stream_inc/stream_inject.h
@@ -0,0 +1,282 @@
+#ifndef _APP_STREAM_INJECT_H_
+#define _APP_STREAM_INJECT_H_
+
+#include <sys/types.h>
+#include <stdint.h>
+#include "stream_base.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define STREAM_INJECT_H_VERSION (20191120)
+
+
+/*
+ CHN : ����GK��غ���
+ ENG : to force terminate a stream;
+
+ MESA_kill_tcp: use RST to terminate a TCP stream;
+ MESA_kill_tcp_synack: send phony SYN/ACK packet to cheat client and server.
+ MESA_kill_connection: for non-TCP stream, such as UDP stream, only available in serial mode.
+
+ return value:
+ >= 0: success.
+ -1 : error.
+*/
+int MESA_kill_tcp(struct streaminfo *stream, const void *raw_pkt);
+int MESA_kill_tcp_synack(struct streaminfo *stream, const void *raw_pkt);
+int MESA_kill_connection(struct streaminfo *stream, const void *ext_raw_pkt);
+
+struct rst_tcp_para{
+ unsigned char th_flags; /* TCPͷ����־λ, ��ѡֵΪ[TH_RST, TH_RST|TH_ACK] */
+ unsigned char rst_pkt_num; /* ����һ��MESA_rst_tcp()���͵�rst������, ��ѡֵ[1,2,3], ��Ե�������, ��rst_pkt_num=2, dir=DIR_DOUBLEʱ,�ܷ���������4�� */
+ /*
+ dir:
+ ����rst������, ��ѡֵΪ[DIR_C2S, DIR_S2C, DIR_DOUBLE], ��ֵ�ο�:streaminfo->curdir,
+ ��������͵İ��뵱ǰ��ͬ��, dir = stream->curdir,
+ ��������͵İ��뵱ǰ������, dir = stream->curdir ^ 3, ������.
+ �����˫����, dir = DIR_DOUBLE;
+ */
+ unsigned char dir;
+ unsigned char __pad_no_use; /* padding for alignment */
+
+ /*
+ rst��ָ����Ϣ, �Ƽ�ֵseed1=65535, seed2Ϊ����, ��13,17,19��;
+ signature_seed1=0 && signature_seed1=0, ��ʾ���ε��ò�ָ��signature, ʹ��ȫ������, ��������:
+ if(sapp.toml->stream.tcp.inject.signature_enabled == 1){
+ signature_seed1 = sapp.toml->stream.tcp.inject.signature_seed1;
+ signature_seed2 = sapp.toml->stream.tcp.inject.signature_seed2;
+ }else{
+ signature_seed1 = rand();
+ signature_seed2 = rand();
+ }
+ */
+ unsigned short signature_seed1;
+ unsigned short signature_seed2;
+};
+
+/*
+ args:
+ stream: ��ǰ��������;
+ paras : ����rst��ز���, ���struct rst_tcp_para�ṹ��˵��;
+ para_len: sizeof(struct rst_tcp_para), Ԥ��������������, ���ݴ˳����жϰ汾.
+
+ MESA_rst_tcp��MESA_kill_tcp����:
+ MESA_kill_tcpʵ�����Ǽ��������Ĵ��ӻ�: ����RST��, ���Ʒ�����APP_STATE_KILL_OTHER, ��DROP��ǰ���������а�;
+ MESA_rst_tcpֻר����һ������: ����RST��!
+
+ note: ������IJ���֮��, kill_tcp����һ��������FD����,
+ ��������Ϊ��������Ŵ���������ʱ��ԭ��, ���µ���FD����Ч, ����MESA_kill_tcp֮������Զ�����FD����,
+ ������MESA_rst_tcp��˵, ������Ϊֻ�Ե�ǰ����Ч,
+ remedy����������������stream��, ��Ҫ����MESA_set_stream_opt(), opt=MSO_TCP_RST_REMEDY ���.
+
+ return value:
+ >= 0: success.
+ -1 : error.
+*/
+int MESA_rst_tcp(struct streaminfo *stream, struct rst_tcp_para *paras, int para_len);
+
+
+
+/*
+ ���������ܵ�MESA_kill_xxxϵ�к���.
+ ���ӹ���Ϊ:
+ ��ʵ�ʷ��͵����ݰ�copy��feedback_buf�ռ���, ������feedback_buf_lenΪʵ�����ݰ�����.
+
+ ע��: feedback_buf_lenΪ���봫����, �����ʾfeedback_buf����, ������ʾʵ�ʷ��͵����ݰ�����.
+
+ return value:
+ >= 0: success.
+ -1 : error.
+ -2 : feedback_buf or feedback_buf_len error.
+*/
+int MESA_kill_tcp_feedback(struct streaminfo *stream, const void *raw_pkt, char *feedback_buf, int *feedback_buf_len);
+int MESA_kill_tcp_synack_feedback(struct streaminfo *stream, const void *raw_pkt, char *feedback_buf, int *feedback_buf_len);
+int MESA_kill_connection_feedback(struct streaminfo *stream, const void *raw_pkt, char *feedback_buf, int *feedback_buf_len);
+
+/*
+ CHN : ����route_dir����, Ϊ�˼���papp;
+ ENG : compat for papp, dir reverse.
+ */
+unsigned char MESA_dir_reverse(unsigned char raw_route_dir);
+
+/***************************************************************************************
+ NOTE:
+ �ڱ���ģʽ��, ����������route_dir�ľ���ֵ, ֻ��Ҫ����ͬ��ͷ��򼴿�,
+ ��������������Ҫ��ȷ����route_dir��0����1, �������������ģʽ��ͬ, ������ʱ��仯,
+ �������ô˽ӿ�, ���ֻ�贫����������ķ���, ���ص�ǰ��·��link route dir,
+ ע��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);
+
+/*
+ ARG:
+ stream: ���ṹ��ָ��;
+ payload: Ҫ���͵�����ָ��;
+ payload_len: Ҫ���͵����ݸ��س���;
+ raw_pkt: ԭʼ��ָ��;
+ snd_routedir: Ҫ�������ݵ�route����,
+ ��������͵İ��뵱ǰ��ͬ��, snd_routedir = stream->routedir,
+ ��������͵İ��뵱ǰ������, snd_routedir = MESA_dir_reverse(stream->routedir).
+ return value:
+ -1: error.
+ >0: ���͵����ݰ�ʵ���ܳ���(payload_len + �ײ��ͷ����);
+*/
+int MESA_inject_pkt(struct streaminfo *stream, const char *payload, int payload_len, const void *raw_pkt, UCHAR snd_routedir);
+
+
+/*
+ ���������ܵ�MESA_inject_pkt_feedback����, ����ͬMESA_inject_pkt().
+ ��ʵ�ʷ��͵����ݰ�copy��feedback_buf�ռ���, ������feedback_buf_lenΪʵ�����ݰ�����.
+
+ ע��: feedback_buf_lenΪ���봫����, �����ʾfeedback_buf����, ������ʾʵ�ʷ��͵����ݰ�����.
+
+ return value:
+ >= 0: success.
+ -1 : error.
+ -2 : feedback_buf or feedback_buf_len error.
+*/
+int MESA_inject_pkt_feedback(struct streaminfo *stream, const char *payload, int payload_len,
+ const void *ext_raw_pkt, UCHAR snd_routedir,
+ char *feedback_buf, int *feedback_buf_len);
+
+int MESA_sendpacket_ethlayer(int thread_index,const char *buf, int buf_len, unsigned int target_id);//papp online, shuihu
+
+/* �����ѹ���õ�����IP��, У��͵Ⱦ�������߼��� */
+int MESA_sendpacket_iplayer(int thread_index,const char *buf, int buf_len, __uint8_t dir);
+
+/* �����ѹ���õ�����IPv4��, ����vxlan����, options��������vxlan��ص�ѡ�� */
+int MESA_sendpacket_iplayer_options(int thread_index,const char *data, int data_len, u_int8_t dir, SAPP_TLV_T *options, int opt_num);
+
+/* �����ѹ���õ�����IPv6��, У��͵Ⱦ�������߼���, ����vxlan����, options��������vxlan��ص�ѡ�� */
+int MESA_sendpacket_ipv6_layer_options(int thread_index,const char *data, int data_len, u_int8_t dir, SAPP_TLV_T *options, int opt_num);
+/* ����ָ������IP��, ��ָ����������, У�����ƽ̨�Զ�����,
+ sip, dip������. */
+int MESA_fakepacket_send_ipv4(int thread_index,__uint8_t ttl,__uint8_t protocol,
+ u_int32_t sip_host_order, u_int32_t dip_host_order,
+ const char *payload, int payload_len,__uint8_t dir);
+
+int MESA_fakepacket_send_ipv4_options(const struct streaminfo *stream, uint8_t protocol,
+ uint32_t sip_host_order, uint32_t dip_host_order,
+ const char *payload, int payload_len, uint8_t dir,
+ SAPP_TLV_T *options, int opt_num);
+
+int MESA_fakepacket_send_ipv4_detail(int thread_index,u_int8_t ttl,
+ u_int8_t protocol,u_int32_t sip, u_int32_t dip, u_int16_t ipid,
+ const char *payload, int payload_len,u_int8_t dir);
+
+int MESA_fakepacket_send_ipv6_options(const struct streaminfo *stream, uint8_t protocol,
+ struct in6_addr *sip, struct in6_addr *dip,
+ const char *payload, int payload_len, uint8_t dir,
+ SAPP_TLV_T *options, int opt_num);
+/* ����ָ������TCP��, ��ָ����������, У�����ƽ̨�Զ�����,
+ sip, dip,sport,dport,sseq,sack��������. */
+int MESA_fakepacket_send_tcp(int thread_index,u_int sip_host_order,u_int dip_host_order,
+ u_short sport_host_order,u_short dport_host_order,
+ u_int sseq_host_order,u_int sack_host_order,
+ u_char control,const char* payload,int payload_len, u_int8_t dir);
+
+int MESA_fakepacket_send_tcp_detail(int thread_index,u_int sip_host_order,u_int dip_host_order,
+ u_short ipid, u_char ip_ttl,
+ u_short sport_host_order,u_short dport_host_order,
+ u_int sseq_host_order,u_int sack_host_order,
+ u_char control, u_short tcp_win, const char* payload,int payload_len, u_int8_t dir);
+int MESA_fakepacket_send_tcp_options(const struct streaminfo *stream,
+ u_int sip_host_order,u_int dip_host_order,
+ u_short sport_host_order,u_short dport_host_order,
+ u_int sseq_host_order,u_int sack_host_order,
+ u_char control,
+ const char* payload,int payload_len, u_int8_t dir,
+ SAPP_TLV_T *options, int opt_num);
+int MESA_fakepacket_send_ipv6_tcp_options(const struct streaminfo *stream,
+ struct in6_addr *sip, struct in6_addr *dip,
+ u_short sport_host_order,u_short dport_host_order,
+ u_int sseq_host_order,u_int sack_host_order,
+ u_char control,
+ const char* payload,int payload_len, u_int8_t dir,
+ SAPP_TLV_T *options, int opt_num);
+/* ����ָ������UDP��, ��ָ����������, У�����ƽ̨�Զ�����,
+ sip, dip,sport,dport��������. */
+int MESA_fakepacket_send_udp(int thread_index, u_int sip_host_order, u_int dip_host_order,
+ u_short sport_host_order,u_short dport_host_order,
+ const char *payload, int payload_len,u_int8_t dir);
+
+int MESA_fakepacket_send_udp_detail(int thread_index, u_int sip_host_order, u_int dip_host_order,
+ u_short ipid, u_int8_t ip_ttl, u_short sport_host_order,u_short dport_host_order,
+ const char *payload, int payload_len,u_int8_t dir);
+int MESA_fakepacket_send_udp_options(const struct streaminfo *stream,
+ u_int sip_host_order, u_int dip_host_order,
+ u_short sport_host_order,u_short dport_host_order,
+ const char *payload, int payload_len,u_int8_t dir,
+ SAPP_TLV_T *options, int opt_num);
+int MESA_fakepacket_send_ipv6_udp_options(const struct streaminfo *stream,
+ struct in6_addr *sip, struct in6_addr *dip,
+ u_short sport_host_order,u_short dport_host_order,
+ const char *payload, int payload_len,u_int8_t dir,
+ SAPP_TLV_T *options, int opt_num);
+/*
+ ת��/���͵�ǰ���������ݰ�,
+ target_id: ����ָ��ת��/����Ŀ��, �������ļ�conf->send_raw_pkt.confָ������Ŀ���������豸��.
+*/
+int sapp_forward_current_pkt(const struct streaminfo *stream, unsigned int target_id);
+
+enum sapp_send_pkt_opt_type{
+ SAPP_SEND_OPT_IP_ID = 0x10,
+ SAPP_SEND_OPT_IP_TTL = 0x11,
+
+ SAPP_SEND_OPT_TCP_WIN = 0x20,
+
+ SAPP_SEND_OPT_GDEV_DMAC = 0x1101, /* GDEV-DMAC, �������������DMAC */
+ SAPP_SEND_OPT_GDEV_SMAC = 0x1102, /* local-SMAC, �������������SMAC */
+ SAPP_SEND_OPT_GDEV_DIP = 0x1103, /* GDEV-DIP, network order */
+ SAPP_SEND_OPT_GDEV_SIP = 0x1104, /* local-SIP, network order */
+ SAPP_SEND_OPT_GDEV_UDP_DPORT=0x1105, /* GDEV udp dst port, network order */
+ SAPP_SEND_OPT_GDEV_UDP_SPORT= 0x1106, /* local udp src port, network order */
+ SAPP_SEND_OPT_VXLAN_FLAGS = 0x1201, /* vxlan ��־λ */
+ SAPP_SEND_OPT_VXLAN_VPN_ID = 0x1202, /* vxlan vlan_id/vpn_id */
+ SAPP_SEND_OPT_VXLAN_LINK_ID = 0x1203, /* vxlan ��·id */
+ SAPP_SEND_OPT_VXLAN_LINK_ENCAP_TYPE = 0x1204, /* vxlanԭʼ�����װ��ʽ */
+ SAPP_SEND_OPT_VXLAN_ONLINE_TEST_FLAG = 0x1205, /* vxlan���߲���λ */
+ SAPP_SEND_OPT_VXLAN_LINK_DIR = 0x1206, /* vxlan��·����λ */
+ SAPP_SEND_OPT_INNER_LINK_ENCAP_TYPE = 1301, /* �ڲ�����װ��ʽ */
+ SAPP_SEND_OPT_INNER_SMAC = 0x1302, /* �ڲ�ԴMAC */
+ SAPP_SEND_OPT_INNER_DMAC = 0x1303, /* �ڲ�Ŀ��MAC */
+ SAPP_SEND_OPT_INNER_VLANID = 0x1304, /* �ڲ������VLAN������ */
+ SAPP_SEND_OPT_VIRTUAL_LINK_ID = 0x1305, /* ����������·�ţ� ͬʱ��Ҫ��TUNNAT_CZ_ACTION_ENCAP_VIRTUAL_LINK_ID*/
+ SAPP_SEND_OPT_REHASH_INDEX = 0x1306, /*����rehash index�� ͬʱ��Ҫ��TUNNAT_CZ_ACTION_ENCAP_VIRTUAL_LINK_ID*/
+};
+
+int MESA_fakepacket_send_ipv4_options(const struct streaminfo *stream, uint8_t protocol,
+ uint32_t sip_host_order, uint32_t dip_host_order,
+ const char *payload, int payload_len, uint8_t dir,
+ SAPP_TLV_T *options, int opt_num);
+
+int MESA_fakepacket_send_tcp_options(const struct streaminfo *stream,
+ u_int sip_host_order,u_int dip_host_order,
+ u_short sport_host_order,u_short dport_host_order,
+ u_int sseq_host_order,u_int sack_host_order,
+ u_char control,
+ const char* payload,int payload_len, u_int8_t dir,
+ SAPP_TLV_T *options, int opt_num);
+
+int MESA_fakepacket_send_udp_options(const struct streaminfo *stream,
+ u_int sip_host_order, u_int dip_host_order,
+ u_short sport_host_order,u_short dport_host_order,
+ const char *payload, int payload_len,u_int8_t dir,
+ SAPP_TLV_T *options, int opt_num);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/include/MESA/stream_inc/stream_project.h b/include/MESA/stream_inc/stream_project.h
new file mode 100644
index 0000000..f28fc17
--- /dev/null
+++ b/include/MESA/stream_inc/stream_project.h
@@ -0,0 +1,160 @@
+#ifndef _STREAM_PROJECT_H_
+#define _STREAM_PROJECT_H_
+
+#include "stream_base.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define STREAM_PROJECT_H_VERSION (20210422)
+
+#define PROJECT_REQ_NAME_MAX_LEN (64)
+
+typedef void (project_req_free_t)(int thread_seq, void *project_req_value);
+
+#define PROJECT_VAL_TYPE_CHAR "char"
+#define PROJECT_VAL_TYPE_SHORT "short"
+#define PROJECT_VAL_TYPE_INT "int"
+#define PROJECT_VAL_TYPE_LONG "long"
+#define PROJECT_VAL_TYPE_STRUCT "struct"
+
+/*
+ CHN : ���ڴ洢ȫ��IP��Ƭԭʼ��
+ ENG : for store all ip frag packet in non-ip-frag entry.
+*/
+#define PROJECT_REQ_IPV4_FRAG_LIST "ipv4_frag_list"
+#define PROJECT_REQ_IPV6_FRAG_LIST "ipv6_frag_list"
+
+
+/*
+ CHN : �˺궨���ʾTCP����ͳ�ƹ�����project_list.conf������, ��Ӧ��project_id��Ҫʹ�����º�����ȡ:
+ ENG : this MARCO is use for tcp flow statistics, should enable this in project_list.conf.
+ project_customer_register(PROJECT_REQ_TCP_FLOW, "struct");
+*/
+#define PROJECT_REQ_TCP_FLOW "tcp_flow_stat"
+
+
+#define PROJECT_REQ_TCP_DEDUCE_FLOW "tcp_deduce_flow_stat"
+
+/*
+ CHN : UDP����ͳ�ƹ���ƽ̨�̶�����, ������project_list.conf����, ��Ӧ��project_id��Ҫʹ�����º�����ȡ:
+ ENG : this MARCO is use for tcp flow statistics, it's always enable.
+ project_customer_register(PROJECT_REQ_UDP_FLOW, "struct");
+*/
+#define PROJECT_REQ_UDP_FLOW "udp_flow_stat"
+
+/*
+ CHN : ������,�ֽ���ͳ��ֵ��pdetail���ƶ���project,�ֽ�����չΪ64bit.
+ ENG : before 2015-12-31, this statistics in struct streaminfo, after 2015-12-31, you must get these use project_req_get_struct().
+*/
+struct tcp_flow_stat
+{
+ UINT32 C2S_all_pkt; /* All tcp packets, include SYN, ACK, FIN, RST, etc. */
+ UINT32 C2S_data_pkt; /* TCP reassemble packet, payload size more than zero, no retransmit packet */
+ UINT32 S2C_all_pkt;
+ UINT32 S2C_data_pkt;
+ UINT64 C2S_all_byte; /* All tcp packet's data size, include retransmit packet */
+ UINT64 C2S_data_byte;
+ UINT64 S2C_all_byte;
+ UINT64 S2C_data_byte;
+
+ /* ������2020-11-17����, �������еײ��ͷ��ԭʼ������, ֮ǰ���ڴ�ṹ����, ��ǰ���� */
+ UINT64 C2S_all_byte_raw;
+ UINT64 S2C_all_byte_raw;
+};
+
+struct udp_flow_stat
+{
+ UINT32 C2S_pkt;
+ UINT32 S2C_pkt;
+ UINT64 C2S_byte;
+ UINT64 S2C_byte;
+
+ /* ������2020-11-17����, �������еײ��ͷ��ԭʼ������, ֮ǰ���ڴ�ṹ����, ��ǰ���� */
+ UINT64 C2S_all_byte_raw;
+ UINT64 S2C_all_byte_raw;
+};
+
+/*
+ must call this function in initialization, only one times,
+ the 'free_cb' should be NULL if 'project_req_val_type' is simple type,
+ otherwise must implement it by youself.
+
+ args:
+ project_req_name: for example, "terminal_tag", "stream_id", "tcp_flow_stat".
+ project_req_val_type: support "char","short","int","long","struct".
+ free_cb: used to free resource when 'project_req_val_type' is "struct".
+
+ return value: 'project_req_id' of this project_req_name, must use this id in following functions.
+ >= 0 : success;
+ -1 : error.
+*/
+int project_producer_register(const char *project_req_name, const char *project_req_val_type, project_req_free_t *free_cb);
+
+/* args and return value same with project_producer_register() */
+int project_customer_register(const char *project_req_name, const char *project_req_val_type);
+
+
+/*
+ Function project_req_add_struct(): 'project_req_value' must be a pointer to heap memory(obtain by malloc).
+
+ return value:
+ 0 : success;
+ -1: error.
+*/
+int project_req_add_char(struct streaminfo *stream, int project_req_id, char project_req_value);
+int project_req_add_short(struct streaminfo *stream, int project_req_id, short project_req_value);
+int project_req_add_int(struct streaminfo *stream, int project_req_id, int project_req_value);
+int project_req_add_long(struct streaminfo *stream, int project_req_id, long project_req_value);
+
+int project_req_add_uchar(struct streaminfo *stream, int project_req_id, unsigned char project_req_value);
+int project_req_add_ushort(struct streaminfo *stream, int project_req_id, unsigned short project_req_value);
+int project_req_add_uint(struct streaminfo *stream, int project_req_id, unsigned int project_req_value);
+int project_req_add_ulong(struct streaminfo *stream, int project_req_id, unsigned long project_req_value);
+
+
+int project_req_add_struct(struct streaminfo *stream, int project_req_id, const void *project_req_value);
+
+
+/*
+ return value:
+ -1(or all bit is '1' in Hex mode, 0xFF, 0xFFFF, etc.):
+ maybe error, maybe the actual project_req_value is -1 indeed,
+ must check tht 'errno' in this case,
+ the 'errno' will be set to 'ERANGE' indicate an error.
+ other: success, get the stored value.
+
+ For example:
+ int value = project_req_get_int(stream, req_id);
+ if((-1 == value) && (ERANGE == errno)){
+ error_handle();
+ }else{
+ // this is not an error!!
+ do_something();
+ }
+*/
+char project_req_get_char(const struct streaminfo *stream, int project_req_id);
+short project_req_get_short(const struct streaminfo *stream, int project_req_id);
+int project_req_get_int(const struct streaminfo *stream, int project_req_id);
+long project_req_get_long(const struct streaminfo *stream, int project_req_id);
+
+unsigned char project_req_get_uchar(const struct streaminfo *stream, int project_req_id);
+unsigned short project_req_get_ushort(const struct streaminfo *stream, int project_req_id);
+unsigned int project_req_get_uint(const struct streaminfo *stream, int project_req_id);
+unsigned long project_req_get_ulong(const struct streaminfo *stream, int project_req_id);
+
+/*
+ return value:
+ NULL : error;
+ others: success.
+*/
+const void *project_req_get_struct(const struct streaminfo *stream, int project_req_id);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/include/MESA/stream_inc/stream_proxy.h b/include/MESA/stream_inc/stream_proxy.h
new file mode 100644
index 0000000..4f8408e
--- /dev/null
+++ b/include/MESA/stream_inc/stream_proxy.h
@@ -0,0 +1,53 @@
+#ifndef _STREAM_PROXY_H_
+#define _STREAM_PROXY_H_
+
+#include "stream_base.h"
+
+#define STREAM_PROXY_H_VERSION (20151230)
+
+
+#define PROXY_STATE_SEL 0
+#define PROXY_STATE_LINK_IN 1
+
+// ������Ϣ
+struct proxydetail
+{
+ UINT16 iType; // ��������, 0 ��ʾ��Ч
+ UINT16 uiPort; // ��������ʵ�������˿�
+ UINT16 uiUserLen;
+ UINT16 uiPwdLen;
+ UINT16 uiApendLen;
+
+ UCHAR pad;
+ UCHAR dealstate; //��������״̬
+ UINT32 uiIP; // ��������ʵ������IP��ַv4, �������ֽ���
+ UCHAR *pIpv6; // ��������ʵ������IP��ַ, v6��ַ
+ UCHAR *pUser; // �����û���
+ UCHAR *pPwd; // ��������
+ UCHAR *append; // ����������Ϣ������url
+ void *apme; //Ӧ�ò�������
+ void *pAllpktpme; //��״̬��tcp����������
+ UINT32 serverpktnum;
+ UINT32 clientpktnum;
+ UINT32 serverbytes;
+ UINT32 clientbytes;
+} ;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*��һ����������Ϣ�����һ��fatherstream,���ҹ��ص�stream��*/
+void set_proxy_fstream(struct streaminfo *pstream,struct streaminfo *pProxy);
+
+/*��������������Ϣ������ɺ󣬽��� �ڲ� ����*/
+int deal_tcp_in_proxy_stream(struct streaminfo *a_tcp,void * a_packet,struct streaminfo *pProxy);
+
+/*�ص��ϲ���Ϣ���ͷŴ�������������Ϣ*/
+void free_tcp_proxy_stream(struct streaminfo *pstream,struct streaminfo *pProxy);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/include/MESA/stream_inc/stream_rawpkt.h b/include/MESA/stream_inc/stream_rawpkt.h
new file mode 100644
index 0000000..df39545
--- /dev/null
+++ b/include/MESA/stream_inc/stream_rawpkt.h
@@ -0,0 +1,112 @@
+#ifndef _APP_STREAM_RAWPKT_H_
+#define _APP_STREAM_RAWPKT_H_
+
+#define STREAM_RAWPKT_H_VERSION (20201104)
+
+#include "stream_base.h"
+
+enum{
+ RAW_PKT_GET_DATA = 1, //return value is 0: out_value should be void **; return value is 1: out_value type is raw_ipfrag_list_t **;
+ RAW_PKT_GET_RAW_PKT_TYPE, //value type: enum addr_type_t in stream_base.h, out_value should be enum addr_type_t*
+ RAW_PKT_GET_TOT_LEN, //value type: int , out_value should be int *
+ RAW_PKT_GET_TIMESTAMP, //value type: struct timeval , out_value should be struct timeval *
+ RAW_PKT_GET_THIS_LAYER_HDR, //value type: void *, out_value should be void **
+ RAW_PKT_GET_THIS_LAYER_REMAIN_LEN, //value type: int , out_value should be int *
+ RAW_PKT_GET_GDEV_IP, // network-order, value type is int, out_value should be int *
+ RAW_PKT_GET_VXLAN_ID, // network-order, LINK_ID, not VPN_ID, value type is int, out_value should be int *
+ RAW_PKT_GET_VXLAN_SPORT, // network-order, value type is short, out_value should be short *
+ RAW_PKT_GET_VXLAN_ENCAP_TYPE, //value type is char,
+ RAW_PKT_GET_VXLAN_LINK_DIR, //value type is char,
+ RAW_PKT_GET_VXLAN_OUTER_GDEV_MAC, //value type is char[6],
+ RAW_PKT_GET_VXLAN_OUTER_LOCAL_MAC, //value type is char[6],
+ RAW_PKT_GET_VIRTUAL_LINK_ID, //value type is uint64 *, out_value should be uint64 *
+ RAW_PKT_GET_REHASH_INDEX, // value type is uint64 *, out_value should be uint64 *
+ RAW_PKT_GET_VXLAN_VPNID, // network-order, VPN_ID, value type is int, out_value should be int *
+ RAW_PKT_GET_VXLAN_LOCAL_IP, // network-order, VXLAN Local IP, value type is int, out_value should be int *
+
+ RAW_PKT_GET_ORIGINAL_LOWEST_ETH_SMAC, /* value type is char[6],��ʵԭʼ��������smac��ַ,mirrorģʽ��, ��ͬ��RAW_PKT_GET_DATA, ����ʹ��stream->pfather����ƫ��; inline + vxlan + mrtunnatģʽ��, ��ͬ��RAW_PKT_GET_VXLAN_OUTER_GDEV_MAC; */
+ RAW_PKT_GET_ORIGINAL_LOWEST_ETH_DMAC, /* value type is char[6],��ʵԭʼ��������dmac��ַ,mirrorģʽ��, ��ͬ��RAW_PKT_GET_DATA, ����ʹ��stream->pfather����ƫ��; inline + vxlan + mrtunnatģʽ��, ��ͬ��RAW_PKT_GET_VXLAN_OUTER_LOCAL_MAC; */
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ get option from raw packet.
+
+for example:
+ CHN : ��ȡԭʼ������, (���ݲ������͵IJ�ͬ, ���ܴ�MAC��ʼ, Ҳ���ܴ�IPͷ����ʼ, ��Ҫʹ��RAW_PKT_GET_RAW_PKT_TYPE��ȡ);
+ ENG : get raw packet header, header's type depend on raw pacekt type, you should use RAW_PKT_GET_RAW_PKT_TYPE first;
+
+ void *raw_pkt_data;
+ ret = get_opt_from_rawpkt(voidpkt, RAW_PKT_GET_DATA, &raw_pkt_data);
+ if(0 == ret){
+ (struct mesa_ethernet_hdr *)raw_pkt_data;
+ }else if(1 == ret){
+ (raw_ipfrag_list_t *)raw_pkt_data;
+ }else{
+ error!
+ }
+
+ CHN : ��ȡԭʼ���ܳ���;
+ ENG : get raw packet size;
+ int tot_len;
+ get_opt_from_rawpkt(voidpkt, RAW_PKT_GET_TOT_LEN, &tot_len);
+
+ CHN : ��ȡ�����ͷ��ʼ��ַ:
+ ENG : get this layer header;
+ void *this_layer_hdr;
+ get_opt_from_rawpkt(voidpkt, RAW_PKT_GET_THIS_LAYER_HDR, &this_layer_hdr);
+
+ CHN : ��ȡԭʼ��ʱ���, ���������ײ㲶���ⲻ֧��ʱ�������, ֵΪȫ0:
+ ENG : get raw packet timestamp, maybe zero if network card or library not support.
+ struct timeval pkt_stamp;
+ get_opt_from_rawpkt(voidpkt, RAW_PKT_GET_TIMESTAMP, &pkt_stamp);
+
+ return value:
+ 1:only for RAW_PKT_GET_DATA type, value is raw_ipfrag_list_t;
+ 0:success;
+ -1:error, or not support.
+*/
+int get_opt_from_rawpkt(const void *rawpkt, int type, void *out_value);
+
+/*
+ CHN: ����ͬ��, ���������ͬ.
+ ENG: Function ibid, except args pstream.
+*/
+int get_rawpkt_opt_from_streaminfo(const struct streaminfo *pstream, int type, void *out_value);
+
+/*
+ ��ȡ��������ԭʼ���ж�Ӧ��ͷ����ַ,
+ ע��: �������������ΪTCP��UDP, ���ô˺�����, �õ�ԭʼ���ж�Ӧ�ij��ر��㴫����IPͷ����ַ.
+*/
+const void *get_this_layer_header(const struct streaminfo *pstream);
+
+/*
+ CHN : ���ݰ�ͷ��ƫ�ƺ���.
+ ENG :
+
+ ����:
+ raw_data: ��ǰ���ͷ��ָ��;
+ raw_layer_type: ��ǰ��ĵ�ַ����, ���: enum addr_type_t ;
+ expect_layer_type: ������ת���ĵ�ַ����, ���: enum addr_type_t ;
+
+ ����ֵ:
+ NULL: �޴˵�ַ;
+ NON-NULL: ��Ӧ���ͷ����ַ.
+
+
+ ����:
+ ���赱ǰ��ΪEthernet, ��ʼ��ͷ��ַΪthis_layer_hdr, ����ת��IPv6��ͷ��:
+ struct ip6_hdr *ip6_header;
+ ip6_header = MESA_jump_layer(this_layer_hdr, ADDR_TYPE_MAC, ADDR_TYPE_IPV6);
+*/
+const void *MESA_jump_layer(const void *raw_data, int raw_layer_type, int expect_layer_type);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/include/MESA/stream_inc/stream_tunnel.h b/include/MESA/stream_inc/stream_tunnel.h
new file mode 100644
index 0000000..bada140
--- /dev/null
+++ b/include/MESA/stream_inc/stream_tunnel.h
@@ -0,0 +1,104 @@
+#ifndef _APP_STREAM_TUNNEL_H_
+#define _APP_STREAM_TUNNEL_H_ 1
+
+#define STREAM_TUNNEL_H_VERSION (20161201)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum tunnel_channel_type_t{
+ TUNNEL_CHANNEL_TYPE_CONTROL = 1, /* ����Э�����ͨ�� */
+ TUNNEL_CHANNEL_TYPE_DATA = 2, /* ����Э������ͨ�� */
+};
+
+enum tunnel_content_type_t{
+ TUNNEL_CONTENT_TYPE_CLEAR = 1, /* �������� */
+ TUNNEL_CONTENT_TYPE_COMPRESS = 2, /* ѹ������ */
+ TUNNEL_CONTENT_TYPE_ENCRYPT = 3, /* �������� */
+};
+
+#define PPTP_ENCRYPT_MPPE (1)
+#define PPTP_ENCRYPT_IPSEC (2)
+#define PPTP_ENCRYPT_PAP (3)
+#define PPTP_ENCRYPT_CHAP (4)
+#define PPTP_ENCRYPT_MS_CHAP (5)
+#define PPTP_ENCRYPT_EAP_TLS (6)
+
+#define PPTP_ENCRYPT_MPPC (100) /* ѹ���㷨, ����־����в�����, ʹ��100, Ԥ������ֵ����չ�ռ� */
+
+typedef struct{
+ int link_type;
+ int encrypt_pro;
+ int authentication_pro;
+ int protocol_compress_enable;
+ int addr_ctrl_compress_enable;
+ int content_type; /* refer to tunnel_content_type_t */
+}pptp_info_t;
+
+
+#define L2TP_ENCRYPT_OTHER (0)
+#define L2TP_ENCRYPT_IPSEC (1)
+#define L2TP_ENCRYPT_NONE (2)
+
+typedef struct{
+ int link_type;
+ int encrypt_pro;
+ int authentication_pro;
+ int protocol_compress_enable;
+ int addr_ctrl_compress_enable;
+ int content_type; /* tunnel_content_type_t */
+ char *chap_username; /* string end with '\0' */
+}l2tp_info_t;
+
+#define IPSEC_VERSION_ISAKMP_V1 (1)
+#define IPSEC_VERSION_IKE_V2 (2)
+
+
+typedef struct{
+ unsigned long long init_cookie;
+ unsigned long long resp_cookie;
+ unsigned short encry_algo;
+ unsigned short hash_algo;
+ unsigned short auth_method;
+ unsigned char upon_udp_nat; /* �Ƿ����UDP-4500�˿ڵ�NAT */
+ unsigned char exchange_type;
+ unsigned char major_version;
+ unsigned char minor_version;
+}isakmp_info_t;
+
+typedef enum{
+ /* NOTE: �ܶ�Э����ص�ֵ��������, ��Ϊ���󲻶�������, ���еĶ��岻�ܸĶ�, ֻ���ٺ���׷����ֵ */
+ TUNNEL_PHONY_PROT_FLAG = 1<<0, /* phony flag, meaningless */
+ IPSEC_OPT_IKE_VERSION = 1<<1, /* opt_val type is int* */
+ IPSEC_OPT_ENCRYPT_ALGO = 1<<2, /* opt_val type is int* */
+ IPSEC_OPT_HASH_ALGO = 1<<3, /* opt_val type is int* */
+ PPTP_OPT_LINK_TYPE = 1<<4, /* opt_val type is int* */
+ PPTP_OPT_ENCRYPT_PRO = 1<<5, /* opt_val type is int* */
+ PPTP_OPT_AUTHEN_PRO = 1<<6, /* opt_val type is int* */
+ PPTP_OPT_COMPRESS_PRO = 1<<7, /* opt_val type is int* */
+ L2TP_OPT_LINK_TYPE = 1<<8, /* opt_val type is int* */
+ L2TP_OPT_ENCRYPT_PRO = 1<<9, /* opt_val type is int* */
+ IPSEC_OPT_EXCHG_MODE = 1<<10, /* opt_val type is uint8*, just a 8bit integer, not string */
+ IPSEC_OPT_IS_NAT = 1<<11, /* opt_val type is uint8*, just a 8bit integer, not string */
+ L2TP_OPT_CHAP_USER_NAME = 1<<12, /* opt_val type is string, end with '\0' */
+ PPTP_CONTENT_TYPE = 1<<13, /* opt_val type is int*, refer to enum tunnel_content_type_t */
+ L2TP_CONTENT_TYPE = 1<<14, /* opt_val type is int*, refer to enum tunnel_content_type_t */
+}tunnel_info_opt_t;
+
+
+struct MESA_tunnel_info{
+ int tunnel_type; /* refer to stream_base.h --> enum stream_type_t */
+ union{
+ pptp_info_t pptp_info;
+ l2tp_info_t l2tp_info;
+ isakmp_info_t isakmp_info;
+ };
+};
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif