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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
|
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <assert.h>
#include <time.h>
#include <arpa/inet.h>
#include "stream.h"
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#include "gtest_sapp_fun.h"
//static gtest_plug_stat_t gtest_tunnel_stat;
static int g_tcp_stream_index = 0;
extern "C" char teredo_unstandard_port_tcp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
const struct tcpdetail *pdetail=(struct tcpdetail *)pstream->pdetail;
int ret;
unsigned short tunnel_type = 0;
int opt_len = sizeof(tunnel_type);
if(OP_STATE_PENDING == pstream->opstate){
ret = MESA_get_stream_opt(pstream, MSO_STREAM_TUNNEL_TYPE, &tunnel_type, &opt_len);
if(ret < 0){
printf("\033[1;31;40mteredo_unstandard_port_tcp_entry: get tunnel type error!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}else{
if(tunnel_type != STREAM_TUNNLE_TEREDO){
printf("\033[1;31;40mteredo_unstandard_port_tcp_entry: tunnel type is not teredo!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
}
}else if(OP_STATE_CLOSE == pstream->opstate){
if((pdetail->serverbytes)
&&(pdetail->serverpktnum)){
printf("\033[32mteredo_unstandard_port_tcp_entry: success!\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
}else{
printf("\033[1;31;40mteredo_unstandard_port_tcp_entry: check data length error!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
}
}
return APP_STATE_GIVEME;
}
extern "C" char teredo_with_auth_hdr_ip6entry(const struct streaminfo *pstream,
unsigned char routedir,int thread_seq, const struct ip6_hdr *ipv6_hdr)
{
if(48 != ntohs(ipv6_hdr->ip6_ctlun.ip6_un1.ip6_un1_plen)){
printf("\033[1;31;40mteredo_with_auth_hdr_ip6entry: ipv6 payload length error!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
if(58 != ipv6_hdr->ip6_ctlun.ip6_un1.ip6_un1_nxt){
printf("\033[1;31;40mteredo_with_auth_hdr_ip6entry: ipv6 next header error!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
if(0xc36ac762 != ipv6_hdr->ip6_src.s6_addr32[3]){
printf("\033[1;31;40mteredo_with_auth_hdr_ip6entry: ipv6 src addr error!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
if(0xfeffffff != ipv6_hdr->ip6_dst.s6_addr32[3]){
printf("\033[1;31;40mteredo_with_auth_hdr_ip6entry: ipv6 src addr error!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
printf("\033[32mteredo_with_auth_hdr_ip6entry: success!\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
return APP_STATE_GIVEME;
}
/* 识别是否是gtp隧道 */
extern "C" char gtp_identify_plug_tcp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
unsigned short tunnel_type;
int opt_len = sizeof(short);
MESA_get_stream_opt(pstream, MSO_STREAM_TUNNEL_TYPE, &tunnel_type, &opt_len);
if(tunnel_type != STREAM_TUNNEL_GPRS_TUNNEL){
printf("\033[1;31;40mstream tunnel is not GTP\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
}else{
printf("\033[32mstream tunnel is GTP\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
}
return APP_STATE_DROPME;
}
/* 识别是否是pptp隧道 */
extern "C" char pptp_identify_plug_tcp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
unsigned short tunnel_type;
int opt_len = sizeof(short);
MESA_get_stream_opt(pstream, MSO_STREAM_TUNNEL_TYPE, &tunnel_type, &opt_len);
if(tunnel_type != STREAM_TUNNLE_PPTP){
printf("\033[1;31;40mstream tunnel is not PPTP\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
}else{
printf("\033[32mstream tunnel is PPTP\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
}
return APP_STATE_DROPME;
}
/* 识别是否是l2tp隧道 */
extern "C" char l2tp_identify_plug_tcp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
unsigned short tunnel_type;
int opt_len = sizeof(short);
MESA_get_stream_opt(pstream, MSO_STREAM_TUNNEL_TYPE, &tunnel_type, &opt_len);
if(tunnel_type != STREAM_TUNNLE_L2TP){
printf("\033[1;31;40mstream tunnel is not L2TP\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
}else{
printf("\033[32mstream tunnel is L2TP\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
}
return APP_STATE_DROPME;
}
/* 不含ppp control, address字段, 识别是否是l2tp隧道 */
extern "C" char l2tp_identify_plug_udp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
unsigned short tunnel_type;
int opt_len = sizeof(short);
if(ntohl(pstream->addr.tuple4_v4->saddr) != 0x0a180024){
/* l2tp底层也是UDP层, port 1701, 不处理这一层 */
return APP_STATE_DROPME;
}
if(ntohs(pstream->addr.tuple4_v4->source) != 52139){
/* l2tp底层也是UDP层, port 1701, 不处理这一层 */
return APP_STATE_DROPME;
}
if(ntohs(pstream->addr.tuple4_v4->source) == 1701){
/* l2tp底层也是UDP层, port 1701, 不处理这一层 */
return APP_STATE_DROPME;
}
MESA_get_stream_opt(pstream, MSO_STREAM_TUNNEL_TYPE, &tunnel_type, &opt_len);
if(tunnel_type != STREAM_TUNNLE_L2TP){
printf("\033[1;31;40mstream tunnel is not L2TP\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
}
printf("\033[32mstream tunnel is L2TP\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
return APP_STATE_DROPME;
}
/* l2tp业务插件 */
extern "C" char l2tp_biz_timeout_entry(stSessionInfo* session_info, void **pme, int thread_seq,struct streaminfo *a_stream,const void *a_packet)
{
/* 超时后解析层先被free, 然后调用业务层插件, 如果能收到CLOSE状态说明正确 */
if(SESSION_STATE_CLOSE == session_info->session_state){
printf("\033[32ml2tp_biz session close, test succ!\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
}
return PROT_STATE_GIVEME;
}
/* 识别是否是teredo隧道 */
extern "C" char teredo_identify_plug_tcp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
unsigned short tunnel_type;
int opt_len = sizeof(short);
MESA_get_stream_opt(pstream, MSO_STREAM_TUNNEL_TYPE, &tunnel_type, &opt_len);
if(tunnel_type != STREAM_TUNNLE_TEREDO){
printf("\033[1;31;40mstream tunnel is not teredo\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
}else{
printf("\033[32mstream tunnel is teredo\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
}
return APP_STATE_DROPME;
}
/* 识别是否是pptp+4over6隧道 */
extern "C" char pptp_and_4over6_identify_plug_tcp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
unsigned short tunnel_type;
int opt_len = sizeof(short);
MESA_get_stream_opt(pstream, MSO_STREAM_TUNNEL_TYPE, &tunnel_type, &opt_len);
if(tunnel_type != (STREAM_TUNNLE_4OVER6|STREAM_TUNNLE_PPTP)){
printf("\033[1;31;40mstream tunnel is not pptp and 4over6\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
}else{
printf("\033[32mstream tunnel is pptp and 4over6\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
}
return APP_STATE_DROPME;
}
/* 识别是否是6over4隧道 */
extern "C" char t6over4_identify_plug_tcp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
unsigned short tunnel_type;
int opt_len = sizeof(short);
MESA_get_stream_opt(pstream, MSO_STREAM_TUNNEL_TYPE, &tunnel_type, &opt_len);
if(tunnel_type != STREAM_TUNNLE_6OVER4){
printf("\033[1;31;40mstream tunnel is not 6over4\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
}else{
printf("\033[32mstream tunnel is 6over4\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
}
return APP_STATE_DROPME;
}
/* 相同的四元组, 不同的mpls地址, 被正确解析成两个不同的流 */
extern "C" char same_tuple4_diff_mpls_two_stream_tcpall_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
if(OP_STATE_CLOSE == pstream->pktstate){
g_tcp_stream_index++;
if(2 != pstream->ptcpdetail->serverpktnum){
printf("\033[1;31;40msame_tuple4_diff_mpls_two_stream_tcpall_entry() error: C2S pkt is not 2!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
}
if(1 != pstream->ptcpdetail->clientpktnum){
printf("\033[1;31;40msame_tuple4_diff_mpls_two_stream_tcpall_entry() error: S2C pkt is not 1!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
}
if(2 == g_tcp_stream_index){
printf("\033[32msame_tuple4_diff_mpls_two_stream_tcpall_entry: success!\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
}
}
return APP_STATE_GIVEME;
}
/* 相同的四元组, 不同的mpls地址, 但是没开启stream_compare_layer.conf, 会被正确解析成一个TCP流 */
extern "C" char same_tuple4_diff_mpls_one_stream_tcpall_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
if(OP_STATE_CLOSE == pstream->pktstate){
g_tcp_stream_index++;
if(4 != pstream->ptcpdetail->serverpktnum){
printf("\033[1;31;40msame_tuple4_diff_mpls_one_stream_tcpall_entry() error: C2S pkt is not 2!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
}
if(2 != pstream->ptcpdetail->clientpktnum){
printf("\033[1;31;40msame_tuple4_diff_mpls_one_stream_tcpall_entry() error: S2C pkt is not 1!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
}
if(1 == g_tcp_stream_index){
printf("\033[32msame_tuple4_diff_mpls_one_stream_tcpall_entry: success!\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
}
}
return APP_STATE_GIVEME;
}
struct gtp_flow_stat{
unsigned int c2s_pkt;
unsigned int c2s_bytes;
unsigned int s2c_pkt;
unsigned int s2c_bytes;
};
/*
内层TCP四元组相同, 但外层GTP四元组不同的流解析测试
pcap包(md5:7db60c7d3bbec640e77499a328ca591b)tcp序号及长度记录:
C2S:
seq:1, len: 247
seq:248, len:318
seq:566, len:308
seq:874, len:101
S2C:
seq:1, len:1360
seq:1361, len:1360
seq:2721, len:563
seq:3284, len:51
seq:3335, len:1360
seq:4695, len:1360
seq:6055, len:1360
seq:7415, len:1360
seq:8775, len:15
*/
extern "C" char gtp_diff_outer_tuple4_tcp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
struct gtp_flow_stat *gtp_tcp_flow;
if(OP_STATE_PENDING == pstream->opstate){
gtp_tcp_flow = (struct gtp_flow_stat *)calloc(1, sizeof(struct gtp_flow_stat));
*pme = gtp_tcp_flow;
}
gtp_tcp_flow = (struct gtp_flow_stat *)(*pme);
if((pstream->ptcpdetail->datalen) > 0 && (pstream->ptcpdetail->pdata != NULL)){
if(DIR_C2S == pstream->curdir){
gtp_tcp_flow->c2s_pkt++;
gtp_tcp_flow->c2s_bytes += pstream->ptcpdetail->datalen;
}else{
gtp_tcp_flow->s2c_pkt++;
gtp_tcp_flow->s2c_bytes += pstream->ptcpdetail->datalen;
}
}
if(OP_STATE_CLOSE == pstream->opstate){
if(22 != pstream->ptcpdetail->serverpktnum){
printf("\033[1;31;40mgtp_diff_outer_tuple4_tcp_entry() error: C2S ALL pkt is not 22!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
}
if(26 != pstream->ptcpdetail->clientpktnum){
printf("\033[1;31;40mgtp_diff_outer_tuple4_tcp_entry() error: S2C ALL pkt is not 26!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
}
if(4 != gtp_tcp_flow->c2s_pkt){
printf("\033[1;31;40mgtp_diff_outer_tuple4_tcp_entry() error: C2S DATA pkt is not 4!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
}
if(9 != gtp_tcp_flow->s2c_pkt){
printf("\033[1;31;40mgtp_diff_outer_tuple4_tcp_entry() error: S2C DATA pkt is not 9, actual is:%u!\033[0m\n", gtp_tcp_flow->s2c_pkt);
sendto_test_result(GTEST_SAPP_ERR);
}
if(974 != gtp_tcp_flow->c2s_bytes){
printf("\033[1;31;40mgtp_diff_outer_tuple4_tcp_entry() error: C2S bytes is not 974, actual is:%u!\033[0m\n", gtp_tcp_flow->c2s_bytes);
sendto_test_result(GTEST_SAPP_ERR);
}
if(8789 != gtp_tcp_flow->s2c_bytes){
printf("\033[1;31;40mgtp_diff_outer_tuple4_tcp_entry() error: S2C bytes is not 8789, actual is:%u!\033[0m\n", gtp_tcp_flow->s2c_bytes);
sendto_test_result(GTEST_SAPP_ERR);
}
free(*pme);
sendto_test_result(GTEST_SAPP_SUCC);
}
return APP_STATE_GIVEME;
}
/*
gtp_diff_external_ip_port_same_inner_tuple4.pcap,
第26个包, C2S方向, 外层源ip由原来的10.7.85.9改成了10.7.85.134, 但是此时TEID没变, 因为TEID的含义是对方定的, 所以下次的回复包才会改;
第28个包, S2C方向, 外层ip地址不变, TEID由38939改成了26892.
*/
extern "C" char gtp_diff_outer_tuple4_track_teid_tcp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
const struct layer_addr_gtp *gtpaddr;
const struct stream_tuple4_v4 *tuple4addr;
char ip_src_str[INET_ADDRSTRLEN], ip_dst_str[INET_ADDRSTRLEN];
gtpaddr = pstream->pfather->addr.gtp;
tuple4addr = pstream->pfather->pfather->addr.tuple4_v4;
if(OP_STATE_PENDING == pstream->opstate){
if(gtpaddr->teid_c2s != ntohl(525653173)){
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in pending state C2S TEID is %u, but expect 525653173!\033[0m\n", ntohl(gtpaddr->teid_c2s));
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
if(gtpaddr->teid_s2c != ntohl(38939)){
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in pending state S2C TEID is %u, but expect 38939!\033[0m\n", ntohl(gtpaddr->teid_s2c));
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
if(tuple4addr->saddr != ntohl(0x0A075509)){
inet_ntop(AF_INET, &tuple4addr->saddr, ip_src_str, sizeof(ip_src_str));
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in pending state outer sip is %s, but expect 10.7.85.9!\033[0m\n", ip_src_str);
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
if(tuple4addr->daddr != ntohl(0x024e3f6f)){
inet_ntop(AF_INET, &tuple4addr->daddr, ip_src_str, sizeof(ip_dst_str));
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in pending state outer dip is %s, but expect 2.78.63.111!\033[0m\n", ip_dst_str);
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
}
if(OP_STATE_CLOSE == pstream->opstate){
if(gtpaddr->teid_c2s != ntohl(525653173)){
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in close state C2S TEID is %u, but expect 525653173!\033[0m\n", ntohl(gtpaddr->teid_c2s));
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
if(gtpaddr->teid_s2c != ntohl(26892)){
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in close state S2C TEID is %u, but expect 26892!\033[0m\n", ntohl(gtpaddr->teid_s2c));
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
if(tuple4addr->saddr != ntohl(0x0A075586)){
inet_ntop(AF_INET, &tuple4addr->saddr, ip_src_str, sizeof(ip_src_str));
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in close state outer sip is %s, but expect 10.7.85.134!\033[0m\n", ip_src_str);
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
if(tuple4addr->daddr != ntohl(0x024e3f6f)){
inet_ntop(AF_INET, &tuple4addr->daddr, ip_src_str, sizeof(ip_dst_str));
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in close state outer dip is %s, but expect 2.78.63.111!\033[0m\n", ip_dst_str);
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
printf("\033[32mgtp_diff_outer_tuple4_track_teid_tcp_entry() test success!\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
}
return APP_STATE_GIVEME;
}
/*
gtp_diff_outer_ip_same_inner_tuple4_s2c.pcap
第5个包, S2C方向, 外层源ip由原来的2.78.63.111改成了2.78.63.254, 但是此时TEID=38939没变, 因为TEID的含义是对方定的, 所以下次的回复包才会改;
第7个包, C2S方向, 外层ip地址不变, TEID由525653173改成了54453.
*/
extern "C" char gtp_diff_outer_tuple4_track_teid_s2c_tcp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
const struct layer_addr_gtp *gtpaddr;
const struct stream_tuple4_v4 *tuple4addr;
char ip_src_str[INET_ADDRSTRLEN], ip_dst_str[INET_ADDRSTRLEN];
gtpaddr = pstream->pfather->addr.gtp;
tuple4addr = pstream->pfather->pfather->addr.tuple4_v4;
if(OP_STATE_PENDING == pstream->opstate){
if(gtpaddr->teid_c2s != ntohl(525653173)){
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in pending state C2S TEID is %u, but expect 525653173!\033[0m\n", ntohl(gtpaddr->teid_c2s));
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
if(gtpaddr->teid_s2c != ntohl(38939)){
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in pending state S2C TEID is %u, but expect 38939!\033[0m\n", ntohl(gtpaddr->teid_s2c));
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
if(tuple4addr->saddr != ntohl(0x0A075509)){
inet_ntop(AF_INET, &tuple4addr->saddr, ip_src_str, sizeof(ip_src_str));
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in pending state outer sip is %s, but expect 10.7.85.9!\033[0m\n", ip_src_str);
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
if(tuple4addr->daddr != ntohl(0x024e3f6f)){
inet_ntop(AF_INET, &tuple4addr->daddr, ip_src_str, sizeof(ip_dst_str));
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in pending state outer dip is %s, but expect 2.78.63.111!\033[0m\n", ip_dst_str);
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
}
if(OP_STATE_CLOSE == pstream->opstate){
if(gtpaddr->teid_c2s != ntohl(54453)){
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in close state C2S TEID is %u, but expect 54453!\033[0m\n", ntohl(gtpaddr->teid_c2s));
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
if(gtpaddr->teid_s2c != ntohl(38939)){
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in close state S2C TEID is %u, but expect 38939!\033[0m\n", ntohl(gtpaddr->teid_s2c));
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
if(tuple4addr->saddr != ntohl(0x0A075509)){
inet_ntop(AF_INET, &tuple4addr->saddr, ip_src_str, sizeof(ip_src_str));
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in close state outer sip is %s, but expect 10.7.85.9!\033[0m\n", ip_src_str);
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
if(tuple4addr->daddr != ntohl(0x024e3ffe)){
inet_ntop(AF_INET, &tuple4addr->daddr, ip_src_str, sizeof(ip_dst_str));
printf("\033[1;31;40mgtp_diff_outer_tuple4_track_teid_tcp_entry() error: in close state outer dip is %s, but expect 2.78.63.254!\033[0m\n", ip_dst_str);
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
printf("\033[32mgtp_diff_outer_tuple4_track_teid_tcp_entry() test success!\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
}
return APP_STATE_GIVEME;
}
/*
本测试插件用于测试完全没有mpls层的Pcap包,
但是开启了非对称mpls对准配置, 即etc/asymmetric_presence_layer.conf,
此时mpls是凭空造出来的, 插件也不应该看到.
*/
extern "C" char pcap_no_mpls_tcp_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
if(ADDR_TYPE_MPLS == pstream->pfather->addr.addrtype){
printf("\033[1;31;40mThis pcap has no MPLS layer actually, but has mpls layer in plugin!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
exit(1);
}
if(OP_STATE_CLOSE == pstream->opstate){
printf("\033[32mpcap_no_mpls_tcp_entry() test success!\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
}
return APP_STATE_GIVEME;
}
/*
之前发生过sapp -d读包模式, 但是overlay_mode=vxlan的情况下, ethernet被认成了是overlay, 导致日志不全缺mac字段.
*/
extern "C" char l2tp_tunnel_stream_pfather_iterate_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
if(pstream->addr.addrtype != ADDR_TYPE_IPV4){
printf("\033[1;31;40maddr type is not tuple4v4!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
pstream = pstream->pfather;
if((NULL == pstream) || (pstream->addr.addrtype != ADDR_TYPE_L2TP)){
printf("\033[1;31;40maddr type is not l2tp!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
pstream = pstream->pfather;
if((pstream->addr.addrtype != ADDR_TYPE_IPV4)){
printf("\033[1;31;40maddr type is not outer tuple4v4!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
pstream = pstream->pfather;
if((pstream->addr.addrtype != ADDR_TYPE_MAC)){
printf("\033[1;31;40maddr type is not mac!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
printf("\033[32ml2tp_tunnel_stream_pfather_iterate_entry() test success!\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
return APP_STATE_DROPME;
}
/*
之前发生过sapp -d读包模式, 但是overlay_mode=vxlan的情况下, ethernet被认成了是overlay, 导致日志不全缺mac字段.
*/
extern "C" char pptp_tunnel_stream_pfather_iterate_entry(struct streaminfo *pstream,void **pme, int thread_seq, void *a_packet)
{
if(pstream->addr.addrtype != ADDR_TYPE_IPV4){
printf("\033[1;31;40maddr type is not tuple4v4!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
pstream = pstream->pfather;
if((pstream->addr.addrtype != ADDR_TYPE_PPTP)){
printf("\033[1;31;40maddr type is not pptp!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
pstream = pstream->pfather;
if((pstream->addr.addrtype != __ADDR_TYPE_IP_PAIR_V4)){
printf("\033[1;31;40maddr type is not outer pure ipv4!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
pstream = pstream->pfather;
if((pstream->addr.addrtype != ADDR_TYPE_MAC)){
printf("\033[1;31;40maddr type is not mac!\033[0m\n");
sendto_test_result(GTEST_SAPP_ERR);
return APP_STATE_DROPME;
}
printf("\033[32mpptp_tunnel_stream_pfather_iterate_entry() test success!\033[0m\n");
sendto_test_result(GTEST_SAPP_SUCC);
return APP_STATE_DROPME;
}
|