TSG-13630 tsg-service-chaining-engine使用mrzcpd捕获报文/回注报文

TSG-13685 tsg-service-chaining-engine使用VXLAN封装Steering/Mirroring的Package
This commit is contained in:
luwenpeng
2023-02-10 14:22:40 +08:00
parent 158e4e89e8
commit 737ca3d4be
23 changed files with 2397 additions and 358 deletions

View File

@@ -0,0 +1,38 @@
#ifndef _CTRL_PACKET_H
#define _CTRL_PACKET_H
#ifdef __cpluscplus
extern "C"
{
#endif
#include <stdint.h>
enum session_state
{
SESSION_STATE_OPENING = 1,
SESSION_STATE_CLONING = 2,
SESSION_STATE_ACTIVE = 3,
SESSION_STATE_RESETALL = 4,
};
struct ctrl_pkt_parser
{
char tsync[4];
uint64_t session_id;
enum session_state state;
int policy_ids[32];
int policy_id_num;
};
void ctrl_packet_parser_init(struct ctrl_pkt_parser *handler);
// return 0 : success
// return -1 : error
int ctrl_packet_parser_parse(struct ctrl_pkt_parser *handler, const void *data, size_t length);
#ifdef __cpluscplus
}
#endif
#endif

52
common/include/g_vxlan.h Normal file
View File

@@ -0,0 +1,52 @@
#ifndef _G_VXLAN_H
#define _G_VXLAN_H
#ifdef __cpluscplus
extern "C"
{
#endif
struct g_vxlan
{
unsigned char flags;
unsigned char reserved[3];
// VNI 3 Bytes
unsigned char vlan_id_half_high;
unsigned char link_layer_type : 4; // 二层报文封装格式
unsigned char vlan_id_half_low : 4;
unsigned int dir_is_e2i : 1;
unsigned int traffic_is_decrypted : 1;
unsigned int chain_index : 5; // max value 32
unsigned int online_test : 1;
// Reserved 1 Bytes
unsigned int r7 : 1;
unsigned int r6 : 1;
unsigned int r5 : 1;
unsigned int r4 : 1;
unsigned int vni_flag : 1;
unsigned int r2 : 1;
unsigned int r1 : 1;
unsigned int r0 : 1;
} __attribute__((__packed__));
void g_vxlan_set_packet_dir(struct g_vxlan *hdr, int dir_is_e2i);
void g_vxlan_set_chain_index(struct g_vxlan *hdr, int chain_index);
void g_vxlan_set_traffic_type(struct g_vxlan *hdr, int traffic_is_decrypted);
int g_vxlan_get_packet_dir(struct g_vxlan *hdr);
int g_vxlan_get_chain_index(struct g_vxlan *hdr);
int g_vxlan_get_traffic_type(struct g_vxlan *hdr);
// return 0 : success
// return -1 : error
int g_vxlan_decode(struct g_vxlan **g_vxlan_hd, const char *raw_data, int raw_len);
#ifdef __cpluscplus
}
#endif
#endif

View File

@@ -11,35 +11,35 @@ extern "C"
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_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_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_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_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),
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,
@@ -47,30 +47,36 @@ enum layer_type
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_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,
};
enum parse_status
struct layer_result
{
PARSE_STATUS_CONTINUE,
PARSE_STATUS_STOP
uint16_t offset;
enum layer_type type;
};
struct raw_pkt_parser;
struct layer_results
{
struct layer_result layers[16];
uint16_t layers_used;
uint16_t layers_size;
};
struct raw_pkt_parser *raw_packet_parser_create(enum layer_type expect_type, uint16_t expect_results_num);
void raw_packet_parser_destory(struct raw_pkt_parser *handler);
struct raw_pkt_parser
{
enum layer_type expect_type;
struct layer_results results;
// return 0 : success
// return -ENOMEM : error
int raw_packet_parser_push(struct raw_pkt_parser *handler, enum layer_type type, uint16_t offset);
// return PARSE_STATUS_CONTINUE
// return PARSE_STATUS_STOP
enum parse_status raw_packet_parser_status(struct raw_pkt_parser *handler, const void *data, enum layer_type this_type);
const void *ptr_pkt_start;
uint64_t pkt_trace_id;
};
void raw_packet_parser_init(struct raw_pkt_parser *handler, uint64_t pkt_trace_id, enum layer_type expect_type, uint16_t expect_results_num);
// return most inner payload
const void *raw_packet_parser_parse(struct raw_pkt_parser *handler, const void *data, size_t length);
@@ -90,4 +96,4 @@ uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum l
}
#endif
#endif
#endif

View File

@@ -9,7 +9,16 @@ extern "C"
#define MIN(a, b) ((a) > (b) ? (a) : (b))
#define LOG_TAG_POLICY "POLICY"
#define LOG_TAG_UTILS "UTILS"
#define LOG_TAG_UTILS "UTILS"
#define LOG_TAG_RAWPKT "RAW_PACKET"
#define LOG_TAG_STABLE "SESSION_TABLE"
#define LOG_TAG_PKTIO "PACKET_IO"
#define LOG_TAG_METRICS "METRICS"
#define LOG_TAG_SCE "SCE"
/******************************************************************************
* fixed_num_array
******************************************************************************/
struct fixed_num_array
{
@@ -21,9 +30,54 @@ struct fixed_num_array
void fixed_num_array_init(struct fixed_num_array *array);
void fixed_num_array_add_elem(struct fixed_num_array *array, int elem);
void fixed_num_array_del_elem(struct fixed_num_array *array, int elem);
int fixed_num_array_is_full(struct fixed_num_array *array);
int fixed_num_array_count_elem(struct fixed_num_array *array);
int fixed_num_array_exist_elem(struct fixed_num_array *array, int elem);
int fixed_num_array_index_elem(struct fixed_num_array *array, int index);
/******************************************************************************
* sids
******************************************************************************/
#include "marsio.h"
struct sids
{
int num;
sid_t elems[MR_SID_LIST_MAXLEN];
};
void sids_write_once(struct sids *dst, struct sids *src);
void sids_copy(struct sids *dst, struct sids *src);
/******************************************************************************
* throughput_metrics
******************************************************************************/
struct throughput_metrics
{
uint64_t n_pkts;
uint64_t n_bytes;
};
void throughput_metrics_inc(struct throughput_metrics *iterm, uint64_t n_pkts, uint64_t n_bytes);
/******************************************************************************
* protocol
******************************************************************************/
void build_udp_header(const char *l3_hdr, int l3_hdr_len, struct udphdr *udp_hdr, u_int16_t udp_sport, u_int16_t udp_dport, int payload_len);
void build_ip_header(struct ip *ip_hdr, u_int8_t next_protocol, const char *src_addr, const char *dst_addr, uint16_t payload_len);
void build_ether_header(struct ethhdr *eth_hdr, uint16_t next_protocol, const char *src_mac, const char *dst_mac);
/******************************************************************************
* device
******************************************************************************/
int get_ip_by_device_name(const char *dev_name, char *ip_buff);
int get_mac_by_device_name(const char *dev_name, char *mac_buff);
int str_to_mac(const char *str, char *mac_buff);
#ifdef __cpluscplus
}
#endif