93 lines
2.2 KiB
C
93 lines
2.2 KiB
C
#ifndef _DATA_PACKET_H
|
|
#define _DATA_PACKET_H
|
|
|
|
#ifdef __cpluscplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
#include <stdint.h>
|
|
|
|
enum layer_type
|
|
{
|
|
// 数据链路层
|
|
LAYER_TYPE_ETHER = 1 << 0,
|
|
LAYER_TYPE_PPP = 1 << 1,
|
|
LAYER_TYPE_HDLC = 1 << 2,
|
|
LAYER_TYPE_L2 = (LAYER_TYPE_ETHER | LAYER_TYPE_PPP | LAYER_TYPE_HDLC),
|
|
|
|
// 数据链路层 -- 隧道
|
|
LAYER_TYPE_VLAN = 1 << 3,
|
|
LAYER_TYPE_PPPOE = 1 << 4,
|
|
LAYER_TYPE_MPLS = 1 << 5,
|
|
LAYER_TYPE_L2_TUN = (LAYER_TYPE_VLAN | LAYER_TYPE_PPPOE | LAYER_TYPE_MPLS),
|
|
|
|
// 网络层
|
|
LAYER_TYPE_IPV4 = 1 << 6,
|
|
LAYER_TYPE_IPV6 = 1 << 7,
|
|
LAYER_TYPE_L3 = (LAYER_TYPE_IPV4 | LAYER_TYPE_IPV6),
|
|
|
|
// 网络层 -- 隧道
|
|
|
|
// 传输层
|
|
LAYER_TYPE_UDP = 1 << 8,
|
|
LAYER_TYPE_TCP = 1 << 9,
|
|
LAYER_TYPE_L4 = (LAYER_TYPE_UDP | LAYER_TYPE_TCP),
|
|
|
|
// 传输层 -- 隧道
|
|
LAYER_TYPE_G_VXLAN = 1 << 10,
|
|
LAYER_TYPE_GTPV1_U = 1 << 11,
|
|
|
|
// ALL
|
|
LAYER_TYPE_ALL = (LAYER_TYPE_L2 | LAYER_TYPE_L2_TUN | LAYER_TYPE_L3 | LAYER_TYPE_L4 | LAYER_TYPE_G_VXLAN | LAYER_TYPE_GTPV1_U),
|
|
|
|
// UNKNOWN
|
|
LAYER_TYPE_UNKNOWN,
|
|
};
|
|
|
|
enum ldbc_method
|
|
{
|
|
LDBC_METHOD_HASH_INT_IP = 1,
|
|
LDBC_METHOD_HASH_EXT_IP = 2,
|
|
LDBC_METHOD_HASH_INT_IP_AND_EXT_IP = 3,
|
|
LDBC_METHOD_HASH_INNERMOST_INT_IP = 4,
|
|
LDBC_METHOD_HASH_INNERMOST_EXT_IP = 5,
|
|
};
|
|
|
|
struct layer_result
|
|
{
|
|
uint16_t offset;
|
|
enum layer_type type;
|
|
};
|
|
|
|
struct data_packet
|
|
{
|
|
struct layer_result layers[16];
|
|
uint16_t layers_used;
|
|
uint16_t layers_size;
|
|
|
|
const void *data_ptr;
|
|
uint64_t trace_id;
|
|
};
|
|
|
|
// return innermost payload
|
|
const void *data_packet_parse(struct data_packet *handler, const void *data, size_t length, uint64_t trace_id);
|
|
|
|
// return 0 : success
|
|
// return -1 : error
|
|
int data_packet_get_innermost_four_tuple(struct data_packet *handler, struct four_tuple *addr);
|
|
int data_packet_get_outermost_four_tuple(struct data_packet *handler, struct four_tuple *addr);
|
|
|
|
// return 0 : success
|
|
// return -1 : error
|
|
int data_packet_get_innermost_address(struct data_packet *handler, struct four_tuple *addr);
|
|
int data_packet_get_outermost_address(struct data_packet *handler, struct four_tuple *addr);
|
|
|
|
uint64_t data_packet_get_hash(struct data_packet *handler, enum ldbc_method method, int dir_is_i2e);
|
|
|
|
#ifdef __cpluscplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|