1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
|