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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
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
|