521 lines
16 KiB
C
521 lines
16 KiB
C
|
|
#ifndef _APP_STREAM_BASE_H_
|
|||
|
|
#define _APP_STREAM_BASE_H_
|
|||
|
|
|
|||
|
|
#define STREAM_BASE_H_VERSION (20170616)
|
|||
|
|
|
|||
|
|
#include <sys/types.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 : <20><><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
/* ENG : stream direction definition*/
|
|||
|
|
#define DIR_C2S 0x01
|
|||
|
|
#define DIR_S2C 0x02
|
|||
|
|
#define DIR_DOUBLE 0x03
|
|||
|
|
|
|||
|
|
/* CHN : <20><><EFBFBD><EFBFBD><EFBFBD>ײ㴫<D7B2>䷽<EFBFBD><E4B7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
/* ENG : network topology route direction, is valid in serial mode */
|
|||
|
|
#define DIR_ROUTE_UP 0x00
|
|||
|
|
#define DIR_ROUTE_DOWN 0x01
|
|||
|
|
|
|||
|
|
/* CHN : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD> */
|
|||
|
|
/* ENG : single packet type definition */
|
|||
|
|
#define PKT_TYPE_NORMAL (0x0) /* normal, common */
|
|||
|
|
#define PKT_TYPE_IPREBUILD (1<<0) /* ip frag reassembled packet; ip<69><70>Ƭ<EFBFBD><C6AC><EFBFBD>鱨<EFBFBD><E9B1A8> */
|
|||
|
|
#define PKT_TYPE_TCPUNORDER (1<<1) /* TCP out of order packet; TCP<43><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
#define PKT_TYPE_TCPREORDER (1<<2) /* TCP sequential packet; TCP<43><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ݰ<EFBFBD> */
|
|||
|
|
#define PKT_TYPE_TCPRETRANS (1<<3) /* TCP retransmit packet; TCP<43>ش<EFBFBD><D8B4><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
#define PKT_TYPE_IP_FRAG (1<<4) /* IP frag packet; IP<49><50>Ƭ<EFBFBD><C6AC> */
|
|||
|
|
#define PKT_TYPE_IP_FRAG_LAST (1<<5) /* last IP frag packet; ͬ<><CDAC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ԭʼ<D4AD><CABC><EFBFBD><EFBFBD>IP<49><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>IP<49><50>Ƭ<EFBFBD><C6AC> */
|
|||
|
|
|
|||
|
|
/* CHN : <20><>ַ<EFBFBD><D6B7><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>, <20><>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> addr_type_to_string() ת<><D7AA><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ʽ. */
|
|||
|
|
/* 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 */
|
|||
|
|
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_MAX, /* 18 */
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
#define TCP_TAKEOVER_STATE_FLAG_OFF 0
|
|||
|
|
#define TCP_TAKEOVER_STATE_FLAG_ON 1
|
|||
|
|
|
|||
|
|
|
|||
|
|
/* CHN : Ӧ<>ò㿴<C3B2><E3BFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD> */
|
|||
|
|
/* ENG : stream state for protocol or business plug*/
|
|||
|
|
#define OP_STATE_PENDING 0
|
|||
|
|
#define OP_STATE_REMOVE_ME 1
|
|||
|
|
#define OP_STATE_CLOSE 2
|
|||
|
|
#define OP_STATE_DATA 3
|
|||
|
|
|
|||
|
|
/* CHN : Ӧ<>ò㷵<C3B2>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
/* 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
|
|||
|
|
|
|||
|
|
/* CHN : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD> */
|
|||
|
|
/* ENG : stream type */
|
|||
|
|
enum stream_type_t{
|
|||
|
|
STREAM_TYPE_NON = 0, /* No stream concept indeed, such as vlan, IP, etc.; <20><><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD>, <20><>VLAN, IP<49><50><EFBFBD><EFBFBD> */
|
|||
|
|
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: <EFBFBD><EFBFBD><EFBFBD>ĵײ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
|
|||
|
|
<EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>stream_type_t, <EFBFBD><EFBFBD><EFBFBD>統ǰ<EFBFBD><EFBFBD>ΪSTREAM_TYPE_TCP, <EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>STREAM_TUNNLE_PPTP.
|
|||
|
|
<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><EFBFBD>ֲ<EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ֻ<EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD>(<EFBFBD><EFBFBD>MAC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
|
*/
|
|||
|
|
enum stream_carry_tunnel_t{
|
|||
|
|
STREAM_TUNNLE_NON = 0, /* default is 0, not tunnel; Ĭ<><C4AC>Ϊ0, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>; */
|
|||
|
|
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,
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
typedef struct raw_ipfrag_list{
|
|||
|
|
void *frag_packet;
|
|||
|
|
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; <20><><EFBFBD><EFBFBD>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)
|
|||
|
|
struct layer_addr_vlan
|
|||
|
|
{
|
|||
|
|
UINT16 vlan_id; /* network order */
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
#define VLAN_ID_LEN 4
|
|||
|
|
struct tuplevlan
|
|||
|
|
{
|
|||
|
|
UCHAR vlan_id[VLAN_ID_LEN];
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
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
|
|||
|
|
{
|
|||
|
|
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,
|
|||
|
|
Ϊ<EFBFBD>˽<EFBFBD>Լ<EFBFBD>ڴ<EFBFBD><EFBFBD>ռ䡢<EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD>, <EFBFBD><EFBFBD>ǿ<EFBFBD>ư<EFBFBD>Э<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD>,
|
|||
|
|
IP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>TCP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
|
|||
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP, <EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD>ϢΪ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,
|
|||
|
|
Ϊ<EFBFBD>˽<EFBFBD>Լ<EFBFBD>ڴ<EFBFBD><EFBFBD>ռ䡢<EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD>, <EFBFBD><EFBFBD>ǿ<EFBFBD>ư<EFBFBD>Э<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD>,
|
|||
|
|
IP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>TCP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
|
|||
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP, <EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD>ϢΪ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_addr_l2tp_v2_t{
|
|||
|
|
UINT16 tunnelid_C2S; /* network order, <20>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>㴴<EFBFBD><E3B4B4><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>Ϊ */
|
|||
|
|
UINT16 tunnelid_S2C; /* network order, <20>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>㴴<EFBFBD><E3B4B4><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>Ϊ */
|
|||
|
|
UINT16 sessionid_C2S; /* network order, <20>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>㴴<EFBFBD><E3B4B4><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>Ϊ */
|
|||
|
|
UINT16 sessionid_S2C; /* network order, <20>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>㴴<EFBFBD><E3B4B4><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>Ϊ */
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
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 layer_addr_mpls
|
|||
|
|
{
|
|||
|
|
unsigned int mpls_pkt[MAX_MPLS_ADDR_LAYER];
|
|||
|
|
char mpls_layer_num;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
struct layer_addr_pptp
|
|||
|
|
{
|
|||
|
|
UINT16 C2S_call_id; /* C2S<32>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD>鷽<EFBFBD><E9B7BD>Ϊ, TCP SYNΪC2S, UDPԴ<50>˿ڴ<CBBF><DAB4><EFBFBD>ΪC2S, callid, network order */
|
|||
|
|
UINT16 S2C_call_id; /* S2Ck<43>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD>鷽<EFBFBD><E9B7BD>Ϊ, TCP SYN/ACKΪS2C, UDPĿ<50>Ķ˿ڴ<CBBF><DAB4><EFBFBD>ΪS2C, callid, network order */
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
struct layer_addr_gtp
|
|||
|
|
{
|
|||
|
|
unsigned long long source;
|
|||
|
|
unsigned int src_seq;
|
|||
|
|
unsigned long long dest;
|
|||
|
|
unsigned int dest_seq;
|
|||
|
|
}__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]; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mac<61><63>ַ, network order */
|
|||
|
|
UCHAR outer_src_mac[MAC_ADDR_LEN]; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mac<61><63>ַ, network order */
|
|||
|
|
UCHAR inner_dst_mac[MAC_ADDR_LEN]; /* <20>ڲ<EFBFBD>mac<61><63>ַ, network order */
|
|||
|
|
UCHAR inner_src_mac[MAC_ADDR_LEN]; /* <20>ڲ<EFBFBD>mac<61><63>ַ, network order */
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
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;
|
|||
|
|
void *paddr;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/* CHN : <20><><EFBFBD><EFBFBD><EFBFBD>˽ṹ<CBBD><E1B9B9><EFBFBD>ں<EFBFBD>papp<70><70><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>ʱ, <20><><EFBFBD><EFBFBD>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; <20>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD>ṹ<EFBFBD><E1B9B9> */
|
|||
|
|
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;
|
|||
|
|
};
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
#ifdef __cplusplus
|
|||
|
|
extern "C" {
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
/* CHN : <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>غ<EFBFBD><D8BA><EFBFBD>, <20><><EFBFBD><EFBFBD>ƽ̨<C6BD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ô<EFBFBD><C3B4>ຯ<EFBFBD><E0BAAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD> */
|
|||
|
|
/* 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 : <20><>ȡ<EFBFBD><C8A1>ǰϵͳ<CFB5><CDB3><EFBFBD>еIJ<D0B5><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
|
/* ENG : get current total thread of platfomr */
|
|||
|
|
int get_thread_count(void);
|
|||
|
|
|
|||
|
|
/* CHN : <20><><EFBFBD><EFBFBD>enum addr_type_tַ<74><D6B7><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>ɿɴ<C9BF>ӡ<EFBFBD><D3A1><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ʽ */
|
|||
|
|
/* 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 : <EFBFBD><EFBFBD>layer_addr<EFBFBD><EFBFBD>ַת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>.
|
|||
|
|
*/
|
|||
|
|
const char *printaddr (const struct layer_addr *paddrinfo, int threadindex);
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
ENG : a reentrant version of printaddr, thread safe;
|
|||
|
|
CHN : printaddr<EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>汾, <EFBFBD><EFBFBD><EFBFBD>̰߳<EFBFBD>ȫ<EFBFBD><EFBFBD>.
|
|||
|
|
*/
|
|||
|
|
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 : <EFBFBD><EFBFBD>layer_addr<EFBFBD><EFBFBD>ַת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>, <EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>ָ<EFBFBD><EFBFBD>Ϊֻ<EFBFBD><EFBFBD>, ʹ<EFBFBD><EFBFBD><EFBFBD>߲<EFBFBD><EFBFBD><EFBFBD>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<EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>汾, <EFBFBD><EFBFBD><EFBFBD>̰߳<EFBFBD>ȫ<EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>ָ<EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṩ<EFBFBD><EFBFBD>out_buf, <EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֯.
|
|||
|
|
*/
|
|||
|
|
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 : <EFBFBD><EFBFBD>layer_addr<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̰߳<EFBFBD>ȫ, <EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>ָ<EFBFBD><EFBFBD>Ϊֻ<EFBFBD><EFBFBD>, ʹ<EFBFBD><EFBFBD><EFBFBD>߲<EFBFBD><EFBFBD><EFBFBD>free..
|
|||
|
|
*/
|
|||
|
|
const char *layer_addr_prefix_ntop(const struct streaminfo *pstream);
|
|||
|
|
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
ENG : duplicate a same layer_addr struct, memory obtained with malloc(3);
|
|||
|
|
CHN : <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>layer_addr<EFBFBD>ṹ<EFBFBD><EFBFBD>, <EFBFBD>ڴ<EFBFBD>ͨ<EFBFBD><EFBFBD>malloc(3)<EFBFBD><EFBFBD>ȡ.
|
|||
|
|
*/
|
|||
|
|
struct layer_addr * layer_addr_dup(const struct layer_addr *paddrinfo);
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
ENG: used to free all memory of paddrinfo;
|
|||
|
|
CHN: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>paddrinfo<EFBFBD>ڴ<EFBFBD>.
|
|||
|
|
*/
|
|||
|
|
void layer_addr_free(struct layer_addr *paddrinfo);
|
|||
|
|
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
ENG : duplicate a same streaminfo list, memory obtained with malloc(3);
|
|||
|
|
CHN : <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>streaminfo<EFBFBD>ṹ<EFBFBD>弰<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ, <EFBFBD>ڴ<EFBFBD>ͨ<EFBFBD><EFBFBD>malloc(3)<EFBFBD><EFBFBD>ȡ.
|
|||
|
|
*/
|
|||
|
|
struct streaminfo *streaminfo_dup(const struct streaminfo *stream);
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
ENG: used to free all memory of streaminfo;
|
|||
|
|
CHN: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷŽṹ<EFBFBD>弰<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>.
|
|||
|
|
*/
|
|||
|
|
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;
|
|||
|
|
|
|||
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ:
|
|||
|
|
>0:ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>ڴ泤<EFBFBD><EFBFBD>, stream_addr_list_ntop()<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ĩβ<EFBFBD><EFBFBD>'\0';
|
|||
|
|
-1:dst<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ䳤<EFBFBD>Ȳ<EFBFBD><EFBFBD><EFBFBD>;
|
|||
|
|
-2:<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|||
|
|
-3:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|||
|
|
*/
|
|||
|
|
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<EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD>, <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ǰIP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭʼ<EFBFBD><EFBFBD>Ƭ<EFBFBD><EFBFBD>.
|
|||
|
|
*/
|
|||
|
|
const raw_ipfrag_list_t *get_raw_frag_list(const struct streaminfo *stream);
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
IP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD>, <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ǰIP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭʼ<EFBFBD><EFBFBD>Ƭ<EFBFBD><EFBFBD>.
|
|||
|
|
*/
|
|||
|
|
const raw_ipfrag_list_t *ip_plug_get_raw_ipfrag_list(int thread_num, enum addr_type_t addr_type);
|
|||
|
|
|
|||
|
|
|
|||
|
|
#ifdef __cplusplus
|
|||
|
|
}
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
#endif
|
|||
|
|
|