forked from chamaken/cgolmnfct
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconntrack_test.go
763 lines (740 loc) · 40.8 KB
/
conntrack_test.go
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
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
package cgolmnfct_test
import (
nfct "github.com/chamaken/cgolmnfct"
. "github.com/chamaken/cgolmnfct/testlib"
mnl "github.com/chamaken/cgolmnl"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"fmt"
"os"
"syscall"
"unsafe"
)
// almost just calling them
var _ = Describe("Cpylmnfct Conntrack", func() {
fmt.Fprintf(os.Stdout, "Hello, conntrack tester!\n")
var (
nlmsgbuf10 []byte
nlmsgbuf11 []byte
nlmsgbuf20 []byte
nlmsgbuf21 []byte
)
BeforeEach(func() {
nlmsgbuf10 = []byte{
// ---------------- ------------------
0xc4, 0x00, 0x00, 0x00, // | 0000000196 | | message length |
0x02, 0x01, 0x00, 0x00, // | 00258 | ---- | | type | flags | IPCTNL_MSG_CT_DELETE
0x00, 0x00, 0x00, 0x00, // | 0000000000 | | sequence number|
0x00, 0x00, 0x00, 0x00, // | 0000000000 | | port ID |
// ---------------- ------------------
0x02, 0x00, 0x00, 0x00, // | 02 00 00 00 | | extra header |
0x34, 0x00, 0x01, 0x80, // |00052|N-|00001| |len |flags| type| + CTA_TUPLE_ORIG
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x08, 0x00, 0x01, 0x00, // |00008|--|00001| |len |flags| type| CTA_IP_V4_SRC
0x01, 0x02, 0x03, 0x04, // | 01 02 03 04 | | data |
0x08, 0x00, 0x02, 0x00, // |00008|--|00002| |len |flags| type| CTA_IP_V4_DST
0xff, 0xfe, 0xfd, 0xfc, // | ff fe fd fc | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTO_NUM
0x11, 0x00, 0x00, 0x00, // | 11 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_PROTO_SRC_PORT
0xf8, 0x8f, 0x00, 0x00, // | f8 8f 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_PROTO_DST_PORT
0x00, 0x35, 0x00, 0x00, // | 00 35 00 00 | | data |
0x34, 0x00, 0x02, 0x80, // |00052|N-|00002| |len |flags| type| + CTA_TUPLE_REPLY
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x08, 0x00, 0x01, 0x00, // |00008|--|00001| |len |flags| type| CTA_IP_V4_SRC
0xff, 0xfe, 0xfd, 0xfc, // | ff fe fd fc | | data |
0x08, 0x00, 0x02, 0x00, // |00008|--|00002| |len |flags| type| CTA_IP_V4_DST
0x01, 0x02, 0x03, 0x04, // | 01 02 03 04 | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTO_NUM
0x11, 0x00, 0x00, 0x00, // | 11 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_PROTO_SRC_PORT
0x00, 0x35, 0x00, 0x00, // | 00 35 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_PROTO_DST_PORT
0xf8, 0x8f, 0x00, 0x00, // | f8 8f 00 00 | | data |
0x08, 0x00, 0x0c, 0x00, // |00008|--|00012| |len |flags| type| CTA_ID *
0x17, 0x6d, 0x0d, 0x78, // | 17 6d 0d 78 | | data |
0x08, 0x00, 0x03, 0x00, // |00008|--|00003| |len |flags| type| CTA_STATUS
0x00, 0x00, 0x00, 0x08, // | 00 00 00 08 | | data | IPS_CONFIRMED
0x1c, 0x00, 0x09, 0x80, // |00028|N-|00009| |len |flags| type| + CTA_COUNTERS_ORIG *
0x0c, 0x00, 0x01, 0x00, // |00012|--|00001| |len |flags| type| CTA_COUNTERS_PACKETS
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x0c, 0x00, 0x02, 0x00, // |00012|--|00002| |len |flags| type| CTA_CONTERS_BYTES
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x1c, 0x00, 0x0a, 0x80, // |00028|N-|00010| |len |flags| type| + CTA_COUNTERS_REPLY *
0x0c, 0x00, 0x01, 0x00, // |00012|--|00001| |len |flags| type| CTA_COUNTERS_PACKETS
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x0c, 0x00, 0x02, 0x00, // |00012|--|00002| |len |flags| type| CTA_CONTERS_BYTES
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
} // ---------------- ------------------
nlmsgbuf11 = []byte{
// ---------------- ------------------
0x84, 0x00, 0x00, 0x00, // | 0000000132 | | message length |
0x02, 0x01, 0x00, 0x00, // | 00258 | ---- | | type | flags | IPCTNL_MSG_CT_DELETE
0x00, 0x00, 0x00, 0x00, // | 0000000000 | | sequence number|
0x00, 0x00, 0x00, 0x00, // | 0000000000 | | port ID |
// ---------------- ------------------
0x02, 0x00, 0x00, 0x00, // | 02 00 00 00 | | extra header |
0x34, 0x00, 0x01, 0x80, // |00052|N-|00001| |len |flags| type| + CTA_TUPLE_ORIG
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x08, 0x00, 0x01, 0x00, // |00008|--|00001| |len |flags| type| CTA_IP_V4_SRC
0x01, 0x02, 0x03, 0x04, // | 01 02 03 04 | | data |
0x08, 0x00, 0x02, 0x00, // |00008|--|00002| |len |flags| type| CTA_IP_V4_DST
0xff, 0xfe, 0xfd, 0xfc, // | ff fe fd fc | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTO_NUM
0x11, 0x00, 0x00, 0x00, // | 11 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_PROTO_SRC_PORT
0xf8, 0x8f, 0x00, 0x00, // | f8 8f 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_PROTO_DST_PORT
0x00, 0x35, 0x00, 0x00, // | 00 35 00 00 | | data |
0x34, 0x00, 0x02, 0x80, // |00052|N-|00002| |len |flags| type| + CTA_TUPLE_REPLY
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x08, 0x00, 0x01, 0x00, // |00008|--|00001| |len |flags| type| CTA_IP_V4_SRC
0xff, 0xfe, 0xfd, 0xfc, // | ff fe fd fc | | data |
0x08, 0x00, 0x02, 0x00, // |00008|--|00002| |len |flags| type| CTA_IP_V4_DST
0x01, 0x02, 0x03, 0x04, // | 01 02 03 04 | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTO_NUM
0x11, 0x00, 0x00, 0x00, // | 11 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_PROTO_SRC_PORT
0x00, 0x35, 0x00, 0x00, // | 00 35 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_PROTO_DST_PORT
0xf8, 0x8f, 0x00, 0x00, // | f8 8f 00 00 | | data |
0x08, 0x00, 0x03, 0x00, // |00008|--|00003| |len |flags| type| CTA_STATUS
0x00, 0x00, 0x00, 0x08, // | 00 00 00 08 | | data | IPS_CONFIRMED
} // ---------------- ------------------
nlmsgbuf20 = []byte{
// ---------------- ------------------
0xdc, 0x00, 0x00, 0x00, // | 0000000220 | | message length |
0x00, 0x01, 0x02, 0x00, // | 00256 | -M-- | | type | flags |
0x00, 0x00, 0x00, 0x00, // | 0000000000 | | sequence number|
0xca, 0x24, 0x00, 0x00, // | 0000009418 | | port ID |
// ---------------- ------------------
0x02, 0x00, 0x00, 0x00, // | 02 00 00 00 | | extra header |
0x34, 0x00, 0x01, 0x80, // |00052|N-|00001| |len |flags| type| + CTA_TUPLE_ORIG
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x08, 0x00, 0x01, 0x00, // |00008|--|00001| |len |flags| type| CTA_IP_V4_SRC
0x01, 0x01, 0x01, 0x01, // | 01 01 01 01 | | data |
0x08, 0x00, 0x02, 0x00, // |00008|--|00002| |len |flags| type| CTA_IP_V4_DST
0x02, 0x02, 0x02, 0x02, // | 02 02 02 02 | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PTOTO_NUM
0x11, 0x00, 0x00, 0x00, // | 11 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_PROTO_SRC_PORT
0x04, 0x64, 0x00, 0x00, // | 04 64 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_PROTO_DST_PORT
0x00, 0xa1, 0x00, 0x00, // | 00 a1 00 00 | | data |
0x34, 0x00, 0x02, 0x80, // |00052|N-|00002| |len |flags| type| + CTA_TUPLE_REPLY
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x08, 0x00, 0x01, 0x00, // |00008|--|00001| |len |flags| type| CTA_TUPLE_V4_SRC
0x01, 0x01, 0x01, 0x01, // | 01 01 01 01 | | data |
0x08, 0x00, 0x02, 0x00, // |00008|--|00002| |len |flags| type| CTA_TUP+E_V4_DST
0x02, 0x02, 0x02, 0x02, // | 02 02 02 02 | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTO_NUM
0x11, 0x00, 0x00, 0x00, // | 11 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_TUPLE_SRC_PORT
0x00, 0xa1, 0x00, 0x00, // | 00 a1 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_TUPLE_DST_PORT
0x04, 0x64, 0x00, 0x00, // | 04 64 00 00 | | data |
0x08, 0x00, 0x03, 0x00, // |00008|--|00003| |len |flags| type| CTA_TUPLE_STATUS
0x00, 0x00, 0x00, 0x0e, // | 00 00 00 0e | | data | IPS_EXPECTED|SEEN_REPLY|ASSURED|CONFIRMED
0x08, 0x00, 0x07, 0x00, // |00008|--|00007| |len |flags| type| CTA_TIMEOUT
0x00, 0x00, 0x00, 0x99, // | 00 00 00 99 | | data |
0x1c, 0x00, 0x09, 0x80, // |00028|N-|00009| |len |flags| type| + CTA_COUNTERS_ORIG *
0x0c, 0x00, 0x01, 0x00, // |00012|--|00001| |len |flags| type| CTA_COUNTERS_PACKETS
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x0c, 0x00, 0x02, 0x00, // |00012|--|00002| |len |flags| type| CTA_COUNTERS_BYTES
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x1c, 0x00, 0x0a, 0x80, // |00028|N-|00010| |len |flags| type| + CTA_COUNTERS_REPLY *
0x0c, 0x00, 0x01, 0x00, // |00012|--|00001| |len |flags| type| CTA_COUNTERS_PACKETS
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x0c, 0x00, 0x02, 0x00, // |00012|--|00002| |len |flags| type| CTA_COUNTERS_BYTES
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x08, 0x00, 0x08, 0x00, // |00008|--|00008| |len |flags| type| CTA_MARK
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x08, 0x00, 0x0c, 0x00, // |00008|--|00012| |len |flags| type| CTA_ID *
0x15, 0x50, 0xb8, 0xb8, // | 15 50 b8 b8 | | data |
0x08, 0x00, 0x0b, 0x00, // |00008|--|00011| |len |flags| type| CTA_USE
0x00, 0x00, 0x00, 0x01, // | 00 00 00 01 | | data |
// ---------------- ------------------
// ---------------- ------------------
0x0c, 0x01, 0x00, 0x00, // | 0000000268 | | message length |
0x00, 0x01, 0x02, 0x00, // | 00256 | -M-- | | type | flags |
0x00, 0x00, 0x00, 0x00, // | 0000000000 | | sequence number|
0xca, 0x24, 0x00, 0x00, // | 0000009418 | | port ID |
// ---------------- ------------------
0x02, 0x00, 0x00, 0x00, // | 02 00 00 00 | | extra header |
0x34, 0x00, 0x01, 0x80, // |00052|N-|00001| |len |flags| type| + CTA_TUPLE_ORIG
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x08, 0x00, 0x01, 0x00, // |00008|--|00001| |len |flags| type| CTA_IP_V4_SRC
0x03, 0x05, 0x05, 0x05, // | 03 03 03 03 | | data |
0x08, 0x00, 0x02, 0x00, // |00008|--|00002| |len |flags| type| CTA_IP_V4_DST
0x06, 0x06, 0x06, 0x06, // | 04 04 04 04 | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTO_NUM
0x06, 0x00, 0x00, 0x00, // | 06 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_PROTO_SRC_PORT
0xc1, 0x79, 0x00, 0x00, // | c1 79 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_PROTO_DST_PORT
0x01, 0xbd, 0x00, 0x00, // | 01 bd 00 00 | | data |
0x34, 0x00, 0x02, 0x80, // |00052|N-|00002| |len |flags| type| + CTA_TUPLE_REPLY
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x06, 0x06, 0x06, 0x06, // |00008|--|00001| |len |flags| type| CTA_IP_V4_SRC
0x04, 0x04, 0x04, 0x04, // | 04 04 04 04 | | data |
0x05, 0x05, 0x05, 0x05, // |00008|--|00002| |len |flags| type| CTA_IP_V4_DST
0x03, 0x03, 0x03, 0x03, // | 03 03 03 03 | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTO_NUM
0x06, 0x00, 0x00, 0x00, // | 06 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_PROTO_SRC_PORT
0x01, 0xbd, 0x00, 0x00, // | 01 bd 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_PROTO_DST_PORT
0xc1, 0x79, 0x00, 0x00, // | c1 79 00 00 | | data |
0x08, 0x00, 0x03, 0x00, // |00008|--|00003| |len |flags| type| CTA_TUPLE_STATUS
0x00, 0x00, 0x00, 0x0e, // | 00 00 00 0e | | data | IPS_EXPECTED|SEEN_REPLY|ASSURED|CONFIRMED
0x08, 0x00, 0x07, 0x00, // |00008|--|00007| |len |flags| type| CTA_TIMEOUT
0x00, 0x06, 0x97, 0x65, // | 00 06 97 65 | | data |
0x1c, 0x00, 0x09, 0x80, // |00028|N-|00009| |len |flags| type| + CTA_COUNTERS_ORIG *
0x0c, 0x00, 0x01, 0x00, // |00012|--|00001| |len |flags| type| CTA_COUNTERS_PACKETS
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x0c, 0x00, 0x02, 0x00, // |00012|--|00002| |len |flags| type| CTA_COUNTERS_BYTES
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x1c, 0x00, 0x0a, 0x80, // |00028|N-|00010| |len |flags| type| + CTA_COUNTERS_REPLY *
0x0c, 0x00, 0x01, 0x00, // |00012|--|00001| |len |flags| type| CTA_COUNTERS_PACKETS
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x0c, 0x00, 0x02, 0x00, // |00012|--|00002| |len |flags| type| CTA_COUNTERS_BYTES
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x30, 0x00, 0x04, 0x80, // |00048|N-|00004| |len |flags| type| + CTA_PROTOINFO
0x2c, 0x00, 0x01, 0x80, // |00044|N-|00001| |len |flags| type| + CTA_PROTOINFO_TCP
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTOINFO_TCP_STATE
0x03, 0x00, 0x00, 0x00, // | 03 00 00 00 | | data |
0x05, 0x00, 0x02, 0x00, // |00005|--|00002| |len |flags| type| CTA_PROTOINFO_TCP_WSCALE_ORIGINAL
0x02, 0x00, 0x00, 0x00, // | 02 00 00 00 | | data |
0x05, 0x00, 0x03, 0x00, // |00005|--|00003| |len |flags| type| CTA_PROTOINFO_TCP_WSCALE_REPLY
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x06, 0x00, 0x04, 0x00, // |00006|--|00004| |len |flags| type| CTA_PROTOINFO_TCP_FLAGS_ORIGINAL
0x23, 0x00, 0x00, 0x00, // | 23 00 00 00 | | data |
0x06, 0x00, 0x05, 0x00, // |00006|--|00005| |len |flags| type| CTA_PROTOINFO_TCP_FLAGS_REPLY
0x23, 0x00, 0x00, 0x00, // | 23 00 00 00 | | data |
0x08, 0x00, 0x08, 0x00, // |00008|--|00008| |len |flags| type| CTA_MARK
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x08, 0x00, 0x0c, 0x00, // |00008|--|00012| |len |flags| type| CTA_ID *
0x14, 0xcc, 0x56, 0x58, // | 14 cc 56 58 | | data |
0x08, 0x00, 0x0b, 0x00, // |00008|--|00011| |len |flags| type| CTA_USE
0x00, 0x00, 0x00, 0x01, // | 00 00 00 01 | | data |
// ---------------- ------------------
// ---------------- ------------------
0xdc, 0x00, 0x00, 0x00, // | 0000000220 | | message length |
0x00, 0x01, 0x02, 0x00, // | 00256 | -M-- | | type | flags |
0x00, 0x00, 0x00, 0x00, // | 0000000000 | | sequence number|
0xca, 0x24, 0x00, 0x00, // | 0000009418 | | port ID |
// ---------------- ------------------
0x02, 0x00, 0x00, 0x00, // | 02 00 00 00 | | extra header |
0x34, 0x00, 0x01, 0x80, // |00052|N-|00001| |len |flags| type| + CTA_TUPLE_ORIG
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x08, 0x00, 0x01, 0x00, // |00008|--|00001| |len |flags| type| CTA_IP_V4_SRC
0x55, 0x55, 0x55, 0x55, // | 55 55 55 55 | | data |
0x08, 0x00, 0x02, 0x00, // |00008|--|00002| |len |flags| type| CTA_IP_V4_DST
0x66, 0x66, 0x66, 0x66, // | 66 66 66 66 | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTO_NUM
0x11, 0x00, 0x00, 0x00, // | 11 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_PROTO_SRC_PORT
0xca, 0xda, 0x00, 0x00, // | ca da 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_PROTO_DST_PORT
0x02, 0x02, 0x00, 0x00, // | 02 02 00 00 | | data |
0x34, 0x00, 0x02, 0x80, // |00052|N-|00002| |len |flags| type| + CTA_TUPLE_REPLY
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x08, 0x00, 0x01, 0x00, // |00008|--|00001| |len |flags| type| CTA_IP_V4_SRC
0x66, 0x66, 0x66, 0x66, // | 66 66 66 66 | | data |
0x08, 0x00, 0x02, 0x00, // |00008|--|00002| |len |flags| type| CTA_IP_V4_DST
0x55, 0x55, 0x55, 0x55, // | 55 55 55 55 | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTO_NUM
0x11, 0x00, 0x00, 0x00, // | 11 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_PROTO_SRC_PORT
0x02, 0x02, 0x00, 0x00, // | 02 02 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_PROTO_DST_PORT
0xca, 0xda, 0x00, 0x00, // | ca da 00 00 | | data |
0x08, 0x00, 0x03, 0x00, // |00008|--|00003| |len |flags| type| CTA_TUPLE_STATUS
0x00, 0x00, 0x00, 0x08, // | 00 00 00 08 | | data | IPS_CONFIRMED
0x08, 0x00, 0x07, 0x00, // |00008|--|00007| |len |flags| type| CTA_TIMEOUT
0x00, 0x00, 0x00, 0x13, // | 00 00 00 13 | | data |
0x1c, 0x00, 0x09, 0x80, // |00028|N-|00009| |len |flags| type| + CTA_COUNTERS_ORIG *
0x0c, 0x00, 0x01, 0x00, // |00012|--|00001| |len |flags| type| CTA_COUNTERS_PACKETS
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x0c, 0x00, 0x02, 0x00, // |00012|--|00002| |len |flags| type| CTA_COUNTERS_BYTES
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x1c, 0x00, 0x0a, 0x80, // |00028|N-|00010| |len |flags| type| + CTA_COUNTERS_REPLY *
0x0c, 0x00, 0x01, 0x00, // |00012|--|00001| |len |flags| type| CTA_COUNTERS_PACKETS
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data | CTA_COUNTERS_BYTES
0x0c, 0x00, 0x02, 0x00, // |00012|--|00002| |len |flags| type|
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x08, 0x00, 0x08, 0x00, // |00008|--|00008| |len |flags| type| CTA_MARK
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x08, 0x00, 0x0c, 0x00, // |00008|--|00012| |len |flags| type| CTA_ID *
0x12, 0xd5, 0x69, 0xe8, // | 12 d5 69 e8 | | data |
0x08, 0x00, 0x0b, 0x00, // |00008|--|00011| |len |flags| type| CTA_USE
0x00, 0x00, 0x00, 0x01, // | 00 00 00 01 | | data |
} // ---------------- ------------------
nlmsgbuf21 = []byte{
// ---------------- ------------------
0x9c, 0x00, 0x00, 0x00, // | 0000000156 | | message length |
0x00, 0x01, 0x02, 0x00, // | 00256 | -M-- | | type | flags |
0x00, 0x00, 0x00, 0x00, // | 0000000000 | | sequence number|
0xca, 0x24, 0x00, 0x00, // | 0000009418 | | port ID |
// ---------------- ------------------
0x02, 0x00, 0x00, 0x00, // | 02 00 00 00 | | extra header |
0x34, 0x00, 0x01, 0x80, // |00052|N-|00001| |len |flags| type| + CTA_TUPLE_ORIG
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x08, 0x00, 0x01, 0x00, // |00008|--|00001| |len |flags| type| CTA_IP_V4_SRC
0x01, 0x01, 0x01, 0x01, // | 01 01 01 01 | | data |
0x08, 0x00, 0x02, 0x00, // |00008|--|00002| |len |flags| type| CTA_IP_V4_DST
0x02, 0x02, 0x02, 0x02, // | 02 02 02 02 | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PTOTO_NUM
0x11, 0x00, 0x00, 0x00, // | 11 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_PROTO_SRC_PORT
0x04, 0x64, 0x00, 0x00, // | 04 64 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_PROTO_DST_PORT
0x00, 0xa1, 0x00, 0x00, // | 00 a1 00 00 | | data |
0x34, 0x00, 0x02, 0x80, // |00052|N-|00002| |len |flags| type| + CTA_TUPLE_REPLY
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x08, 0x00, 0x01, 0x00, // |00008|--|00001| |len |flags| type| CTA_TUPLE_V4_SRC
0x01, 0x01, 0x01, 0x01, // | 01 01 01 01 | | data |
0x08, 0x00, 0x02, 0x00, // |00008|--|00002| |len |flags| type| CTA_TUP+E_V4_DST
0x02, 0x02, 0x02, 0x02, // | 02 02 02 02 | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTO_NUM
0x11, 0x00, 0x00, 0x00, // | 11 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_TUPLE_SRC_PORT
0x00, 0xa1, 0x00, 0x00, // | 00 a1 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_TUPLE_DST_PORT
0x04, 0x64, 0x00, 0x00, // | 04 64 00 00 | | data |
0x08, 0x00, 0x03, 0x00, // |00008|--|00003| |len |flags| type| CTA_TUPLE_STATUS
0x00, 0x00, 0x00, 0x0e, // | 00 00 00 0e | | data | IPS_EXPECTED|SEEN_REPLY|ASSURED|CONFIRMED
0x08, 0x00, 0x07, 0x00, // |00008|--|00007| |len |flags| type| CTA_TIMEOUT
0x00, 0x00, 0x00, 0x99, // | 00 00 00 99 | | data |
0x08, 0x00, 0x08, 0x00, // |00008|--|00008| |len |flags| type| CTA_MARK
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x08, 0x00, 0x0b, 0x00, // |00008|--|00011| |len |flags| type| CTA_USE
0x00, 0x00, 0x00, 0x01, // | 00 00 00 01 | | data |
// ---------------- ------------------
// ---------------- ------------------
0xcc, 0x00, 0x00, 0x00, // | 0000000204 | | message length |
0x00, 0x01, 0x02, 0x00, // | 00256 | -M-- | | type | flags |
0x00, 0x00, 0x00, 0x00, // | 0000000000 | | sequence number|
0xca, 0x24, 0x00, 0x00, // | 0000009418 | | port ID |
// ---------------- ------------------
0x02, 0x00, 0x00, 0x00, // | 02 00 00 00 | | extra header |
0x34, 0x00, 0x01, 0x80, // |00052|N-|00001| |len |flags| type| + CTA_TUPLE_ORIG
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x08, 0x00, 0x01, 0x00, // |00008|--|00001| |len |flags| type| CTA_IP_V4_SRC
0x03, 0x05, 0x05, 0x05, // | 03 03 03 03 | | data |
0x08, 0x00, 0x02, 0x00, // |00008|--|00002| |len |flags| type| CTA_IP_V4_DST
0x06, 0x06, 0x06, 0x06, // | 04 04 04 04 | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTO_NUM
0x06, 0x00, 0x00, 0x00, // | 06 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_PROTO_SRC_PORT
0xc1, 0x79, 0x00, 0x00, // | c1 79 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_PROTO_DST_PORT
0x01, 0xbd, 0x00, 0x00, // | 01 bd 00 00 | | data |
0x34, 0x00, 0x02, 0x80, // |00052|N-|00002| |len |flags| type| + CTA_TUPLE_REPLY
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x06, 0x06, 0x06, 0x06, // |00008|--|00001| |len |flags| type| CTA_IP_V4_SRC
0x04, 0x04, 0x04, 0x04, // | 04 04 04 04 | | data |
0x05, 0x05, 0x05, 0x05, // |00008|--|00002| |len |flags| type| CTA_IP_V4_DST
0x03, 0x03, 0x03, 0x03, // | 03 03 03 03 | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTO_NUM
0x06, 0x00, 0x00, 0x00, // | 06 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_PROTO_SRC_PORT
0x01, 0xbd, 0x00, 0x00, // | 01 bd 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_PROTO_DST_PORT
0xc1, 0x79, 0x00, 0x00, // | c1 79 00 00 | | data |
0x08, 0x00, 0x03, 0x00, // |00008|--|00003| |len |flags| type| CTA_TUPLE_STATUS
0x00, 0x00, 0x00, 0x0e, // | 00 00 00 0e | | data | IPS_EXPECTED|SEEN_REPLY|ASSURED|CONFIRMED
0x08, 0x00, 0x07, 0x00, // |00008|--|00007| |len |flags| type| CTA_TIMEOUT
0x00, 0x06, 0x97, 0x65, // | 00 06 97 65 | | data |
0x30, 0x00, 0x04, 0x80, // |00048|N-|00004| |len |flags| type| + CTA_PROTOINFO
0x2c, 0x00, 0x01, 0x80, // |00044|N-|00001| |len |flags| type| + CTA_PROTOINFO_TCP
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTOINFO_TCP_STATE
0x03, 0x00, 0x00, 0x00, // | 03 00 00 00 | | data |
0x05, 0x00, 0x02, 0x00, // |00005|--|00002| |len |flags| type| CTA_PROTOINFO_TCP_WSCALE_ORIGINAL
0x02, 0x00, 0x00, 0x00, // | 02 00 00 00 | | data |
0x05, 0x00, 0x03, 0x00, // |00005|--|00003| |len |flags| type| CTA_PROTOINFO_TCP_WSCALE_REPLY
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x06, 0x00, 0x04, 0x00, // |00006|--|00004| |len |flags| type| CTA_PROTOINFO_TCP_FLAGS_ORIGINAL
0x23, 0x00, 0x00, 0x00, // | 23 00 00 00 | | data |
0x06, 0x00, 0x05, 0x00, // |00006|--|00005| |len |flags| type| CTA_PROTOINFO_TCP_FLAGS_REPLY
0x23, 0x00, 0x00, 0x00, // | 23 00 00 00 | | data |
0x08, 0x00, 0x08, 0x00, // |00008|--|00008| |len |flags| type| CTA_MARK
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x08, 0x00, 0x0b, 0x00, // |00008|--|00011| |len |flags| type| CTA_USE
0x00, 0x00, 0x00, 0x01, // | 00 00 00 01 | | data |
// ---------------- ------------------
// ---------------- ------------------
0x9c, 0x00, 0x00, 0x00, // | 0000000156 | | message length |
0x00, 0x01, 0x02, 0x00, // | 00256 | -M-- | | type | flags |
0x00, 0x00, 0x00, 0x00, // | 0000000000 | | sequence number|
0xca, 0x24, 0x00, 0x00, // | 0000009418 | | port ID |
// ---------------- ------------------
0x02, 0x00, 0x00, 0x00, // | 02 00 00 00 | | extra header |
0x34, 0x00, 0x01, 0x80, // |00052|N-|00001| |len |flags| type| + CTA_TUPLE_ORIG
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x08, 0x00, 0x01, 0x00, // |00008|--|00001| |len |flags| type| CTA_IP_V4_SRC
0x55, 0x55, 0x55, 0x55, // | 55 55 55 55 | | data |
0x08, 0x00, 0x02, 0x00, // |00008|--|00002| |len |flags| type| CTA_IP_V4_DST
0x66, 0x66, 0x66, 0x66, // | 66 66 66 66 | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTO_NUM
0x11, 0x00, 0x00, 0x00, // | 11 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_PROTO_SRC_PORT
0xca, 0xda, 0x00, 0x00, // | ca da 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_PROTO_DST_PORT
0x02, 0x02, 0x00, 0x00, // | 02 02 00 00 | | data |
0x34, 0x00, 0x02, 0x80, // |00052|N-|00002| |len |flags| type| + CTA_TUPLE_REPLY
0x14, 0x00, 0x01, 0x80, // |00020|N-|00001| |len |flags| type| + CTA_TUPLE_IP
0x08, 0x00, 0x01, 0x00, // |00008|--|00001| |len |flags| type| CTA_IP_V4_SRC
0x66, 0x66, 0x66, 0x66, // | 66 66 66 66 | | data |
0x08, 0x00, 0x02, 0x00, // |00008|--|00002| |len |flags| type| CTA_IP_V4_DST
0x55, 0x55, 0x55, 0x55, // | 55 55 55 55 | | data |
0x1c, 0x00, 0x02, 0x80, // |00028|N-|00002| |len |flags| type| + CTA_TUPLE_PROTO
0x05, 0x00, 0x01, 0x00, // |00005|--|00001| |len |flags| type| CTA_PROTO_NUM
0x11, 0x00, 0x00, 0x00, // | 11 00 00 00 | | data |
0x06, 0x00, 0x02, 0x00, // |00006|--|00002| |len |flags| type| CTA_PROTO_SRC_PORT
0x02, 0x02, 0x00, 0x00, // | 02 02 00 00 | | data |
0x06, 0x00, 0x03, 0x00, // |00006|--|00003| |len |flags| type| CTA_PROTO_DST_PORT
0xca, 0xda, 0x00, 0x00, // | ca da 00 00 | | data |
0x08, 0x00, 0x03, 0x00, // |00008|--|00003| |len |flags| type| CTA_TUPLE_STATUS
0x00, 0x00, 0x00, 0x08, // | 00 00 00 08 | | data | IPS_CONFIRMED
0x08, 0x00, 0x07, 0x00, // |00008|--|00007| |len |flags| type| CTA_TIMEOUT
0x00, 0x00, 0x00, 0x13, // | 00 00 00 13 | | data |
0x08, 0x00, 0x08, 0x00, // |00008|--|00008| |len |flags| type| CTA_MARK
0x00, 0x00, 0x00, 0x00, // | 00 00 00 00 | | data |
0x08, 0x00, 0x0b, 0x00, // |00008|--|00011| |len |flags| type| CTA_USE
0x00, 0x00, 0x00, 0x01, // | 00 00 00 01 | | data |
} // ---------------- ------------------
})
Context("Construct and Destruct", func() {
It("should success", func() {
ct, err := nfct.NewConntrack()
defer ct.Destroy()
Expect(err).To(BeNil())
})
})
Context("Clone", func() {
It("should have different addr", func() {
ct, _ := nfct.NewConntrack()
defer ct.Destroy()
clone, err := ct.Clone()
Expect(err).To(BeNil())
defer clone.Destroy()
Expect(ct == clone).To(BeFalse())
})
It("should have same attr value", func() {
ct, _ := nfct.NewConntrack()
defer ct.Destroy()
ct.SetAttrU8(nfct.ATTR_ORIG_L3PROTO, 11)
clone, err := ct.Clone()
Expect(err).To(BeNil())
defer clone.Destroy()
v, _ := clone.AttrU8(nfct.ATTR_ORIG_L3PROTO)
Expect(v).To(Equal(uint8(11)))
})
})
Context("Objopt", func() {
It("should same - set/get", func() {
ct, _ := nfct.NewConntrack()
defer ct.Destroy()
// ct.SetAttrU32(nfct.ATTR_STATUS, uint32(nfct.IPS_SRC_NAT_DONE))
ct.SetAttrU8(nfct.ATTR_ORIG_L3PROTO, 2) // AF_INET
ct.SetAttrU32(nfct.ATTR_REPL_IPV4_DST, 1)
opt, err := ct.Objopt(nfct.NFCT_GOPT_IS_SNAT)
Expect(err).To(BeNil())
Expect(opt).To(Equal(1))
err = ct.Setobjopt(nfct.NFCT_SOPT_UNDO_SNAT)
Expect(err).To(BeNil())
opt, err = ct.Objopt(nfct.NFCT_GOPT_IS_SNAT)
Expect(err).To(BeNil())
Expect(opt).To(Equal(0))
})
})
Context("Attr", func() {
It("should have set by set_l", func() {
var attr1, attr2 uint32
attr1 = 0x12345678
ct, _ := nfct.NewConntrack()
defer ct.Destroy()
err := ct.SetAttrL(nfct.ATTR_ORIG_IPV4_SRC, unsafe.Pointer(&attr1), 4)
Expect(err).To(BeNil())
p, _ := ct.Attr(nfct.ATTR_ORIG_IPV4_SRC)
attr2 = *((*uint32)(p))
// attr2, _ = ct.AttrU32(nfct.ATTR_ORIG_IPV4_SRC)
Expect(attr2).To(Equal(attr1))
attr1 = 0x9abcdef0
err = ct.SetAttrLPtr(nfct.ATTR_ORIG_IPV4_SRC, &attr1)
Expect(err).To(BeNil())
p, _ = ct.Attr(nfct.ATTR_ORIG_IPV4_SRC)
attr2 = *((*uint32)(p))
// attr2, _ = ct.AttrU32(nfct.ATTR_ORIG_IPV4_SRC)
Expect(attr2).To(Equal(attr1))
})
It("should set/get by simple set/get", func() {
var attr1, attr2 uint32
attr1 = 0x12345678
ct, _ := nfct.NewConntrack()
defer ct.Destroy()
err := ct.SetAttr(nfct.ATTR_ORIG_IPV4_SRC, unsafe.Pointer(&attr1))
Expect(err).To(BeNil())
p, err := ct.Attr(nfct.ATTR_ORIG_IPV4_SRC)
Expect(err).To(BeNil())
attr2 = *((*uint32)(p))
Expect(attr2).To(Equal(attr1))
attr1 = 0x9abcdef0
err = ct.SetAttrPtr(nfct.ATTR_ORIG_IPV4_SRC, &attr1)
Expect(err).To(BeNil())
p, _ = ct.Attr(nfct.ATTR_ORIG_IPV4_SRC)
attr2 = *((*uint32)(p))
Expect(attr2).To(Equal(attr1))
})
It("should set/get u8", func() {
ct, _ := nfct.NewConntrack()
defer ct.Destroy()
err := ct.SetAttrU8(nfct.ATTR_ORIG_L3PROTO, 123)
Expect(err).To(BeNil())
ret, err := ct.AttrU8(nfct.ATTR_ORIG_L3PROTO)
Expect(err).To(BeNil())
Expect(ret).To(Equal(uint8(123)))
})
It("should set/get u16", func() {
ct, _ := nfct.NewConntrack()
defer ct.Destroy()
err := ct.SetAttrU16(nfct.ATTR_ORIG_PORT_SRC, 0x1234)
Expect(err).To(BeNil())
ret, err := ct.AttrU16(nfct.ATTR_ORIG_PORT_SRC)
Expect(err).To(BeNil())
Expect(ret).To(Equal(uint16(0x1234)))
})
It("should set/get u32", func() {
ct, _ := nfct.NewConntrack()
defer ct.Destroy()
err := ct.SetAttrU32(nfct.ATTR_ORIG_IPV4_DST, 0x12345678)
Expect(err).To(BeNil())
ret, err := ct.AttrU32(nfct.ATTR_ORIG_IPV4_DST)
Expect(err).To(BeNil())
Expect(ret).To(Equal(uint32(0x12345678)))
})
It("should set/get u64", func() {
ct, _ := nfct.NewConntrack()
defer ct.Destroy()
err := ct.SetAttrU64(nfct.ATTR_DCCP_HANDSHAKE_SEQ, 0x123456789abcdef0)
Expect(err).To(BeNil())
ret, err := ct.AttrU64(nfct.ATTR_DCCP_HANDSHAKE_SEQ)
Expect(err).To(BeNil())
Expect(ret).To(Equal(uint64(0x123456789abcdef0)))
})
It("should true set attr", func() {
ct, _ := nfct.NewConntrack()
defer ct.Destroy()
ct.SetAttrU64(nfct.ATTR_DCCP_HANDSHAKE_SEQ, 0x123456789abcdef0)
ret, err := ct.AttrIsSet(nfct.ATTR_DCCP_HANDSHAKE_SEQ)
Expect(err).To(BeNil())
Expect(ret).To(BeTrue())
ret, err = ct.AttrIsSet(nfct.ATTR_ORIG_COUNTER_PACKETS)
Expect(err).To(BeNil())
Expect(ret).To(BeFalse())
})
It("should true set attrs", func() {
ct, _ := nfct.NewConntrack()
defer ct.Destroy()
a := []nfct.ConntrackAttr{nfct.ATTR_ORIG_L3PROTO, nfct.ATTR_ORIG_PORT_SRC,
nfct.ATTR_ORIG_IPV4_DST, nfct.ATTR_ORIG_COUNTER_PACKETS}
ct.SetAttrU8(nfct.ATTR_ORIG_L3PROTO, 123)
ct.SetAttrU16(nfct.ATTR_ORIG_PORT_SRC, 0x1234)
ct.SetAttrU32(nfct.ATTR_ORIG_IPV4_DST, 0x12345678)
ret, err := ct.AttrIsSetArray(a[:3])
Expect(err).To(BeNil())
Expect(ret).To(BeTrue())
ret, err = ct.AttrIsSetArray(a)
Expect(err).To(BeNil())
Expect(ret).To(BeFalse())
})
It("should unset", func() {
ct, _ := nfct.NewConntrack()
ct.Destroy()
ct.SetAttrU8(nfct.ATTR_ORIG_L3PROTO, 123)
ret, _ := ct.AttrIsSet(nfct.ATTR_ORIG_L3PROTO)
Expect(ret).To(BeTrue())
err := ct.AttrUnset(nfct.ATTR_ORIG_L3PROTO)
Expect(err).To(BeNil())
ret, _ = ct.AttrIsSet(nfct.ATTR_ORIG_L3PROTO)
Expect(ret).To(BeFalse())
})
})
Context("Attr group", func() {
var grp1, grp2 *nfct.AttrGrpIpv4
BeforeEach(func() {
grp1 = &nfct.AttrGrpIpv4{Src: 0x12345678, Dst: 0x9abcdef0}
grp2 = &nfct.AttrGrpIpv4{}
})
It("shoule set/get group", func() {
ct, _ := nfct.NewConntrack()
defer ct.Destroy()
err := ct.SetAttrGrp(nfct.ATTR_GRP_ORIG_IPV4, unsafe.Pointer(grp1))
Expect(err).To(BeNil())
err = ct.AttrGrp(nfct.ATTR_GRP_ORIG_IPV4, unsafe.Pointer(grp2))
Expect(err).To(BeNil())
Expect(*grp2).To(Equal(*grp1))
err = ct.SetAttrGrpPtr(nfct.ATTR_GRP_REPL_IPV4, grp1)
Expect(err).To(BeNil())
err = ct.AttrGrpPtr(nfct.ATTR_GRP_REPL_IPV4, grp2)
Expect(err).To(BeNil())
Expect(*grp2).To(Equal(*grp1))
})
It("should be able to unset", func() {
ct, _ := nfct.NewConntrack()
defer ct.Destroy()
err := ct.SetAttrGrp(nfct.ATTR_GRP_ORIG_IPV4, unsafe.Pointer(grp1))
Expect(err).To(BeNil())
ret, err := ct.AttrGrpIsSet(nfct.ATTR_GRP_ORIG_IPV4)
Expect(err).To(BeNil())
Expect(ret).To(BeTrue())
err = ct.AttrGrpUnset(nfct.ATTR_GRP_ORIG_IPV4)
Expect(err).To(BeNil())
ret, err = ct.AttrGrpIsSet(nfct.ATTR_GRP_ORIG_IPV4)
Expect(err).To(BeNil())
Expect(ret).To(BeFalse())
})
})
Context("cmp", func() {
It("shoule work with NFCT_CMP_ALL and STRICT flag", func() {
ct1, _ := nfct.NewConntrack()
defer ct1.Destroy()
ct2, _ := nfct.NewConntrack()
defer ct2.Destroy()
grp := &nfct.AttrGrpIpv4{Src: 0x12345678, Dst: 0x9abcdef0}
ct1.SetAttrGrpPtr(nfct.ATTR_GRP_ORIG_IPV4, grp)
ct1.SetAttrU8(nfct.ATTR_ORIG_L3PROTO, 123)
ct1.SetAttrU16(nfct.ATTR_ORIG_PORT_SRC, 0x1234)
ct1.SetAttrU32(nfct.ATTR_ORIG_IPV4_DST, 0x12345678)
ct1.SetAttrU64(nfct.ATTR_ID, 0xabcdef) // STRICT is only for meta
ct2.SetAttrGrpPtr(nfct.ATTR_GRP_ORIG_IPV4, grp)
ct2.SetAttrU8(nfct.ATTR_ORIG_L3PROTO, 123)
ct2.SetAttrU16(nfct.ATTR_ORIG_PORT_SRC, 0x1234)
ct2.SetAttrU32(nfct.ATTR_ORIG_IPV4_DST, 0x87654321)
Expect(ct1.Cmp(ct2, nfct.NFCT_CMP_ALL)).To(BeZero())
ct2.SetAttrU32(nfct.ATTR_ORIG_IPV4_DST, 0x12345678)
Expect(ct1.Cmp(ct2, nfct.NFCT_CMP_ALL)).To(Equal(1))
Expect(ct1.Cmp(ct2, nfct.NFCT_CMP_STRICT)).To(BeZero())
ct2.SetAttrU64(nfct.ATTR_ID, 0xabcdef)
Expect(ct1.Cmp(ct2, nfct.NFCT_CMP_STRICT)).To(Equal(1))
})
})
Context("copy", func() {
It("should have same attrs", func() {
ct1, _ := nfct.NewConntrack()
defer ct1.Destroy()
ct2, _ := nfct.NewConntrack()
defer ct2.Destroy()
ct1.SetAttrU8(nfct.ATTR_ORIG_L3PROTO, 123)
ct1.SetAttrU16(nfct.ATTR_ORIG_PORT_SRC, 0x1234)
ct1.Copy(ct2, nfct.NFCT_CP_ALL)
ret8, _ := ct2.AttrU8(nfct.ATTR_ORIG_L3PROTO)
Expect(ret8).To(Equal(uint8(123)))
ret16, _ := ct2.AttrU16(nfct.ATTR_ORIG_PORT_SRC)
Expect(ret16).To(Equal(uint16(0x1234)))
})
It("shoule copy only specified attr", func() {
ct1, _ := nfct.NewConntrack()
defer ct1.Destroy()
ct2, _ := nfct.NewConntrack()
defer ct2.Destroy()
ct1.SetAttrU8(nfct.ATTR_ORIG_L3PROTO, 123)
ct1.SetAttrU16(nfct.ATTR_ORIG_PORT_SRC, 0x1234)
ct1.CopyAttr(ct2, nfct.ATTR_ORIG_L3PROTO)
ret8, _ := ct2.AttrU8(nfct.ATTR_ORIG_L3PROTO)
Expect(ret8).To(Equal(uint8(123)))
_, err := ct2.AttrU16(nfct.ATTR_ORIG_PORT_SRC)
Expect(err).To(Equal(syscall.ENODATA))
})
})
Context("parse and build", func() {
It("should have same value", func() {
ct, _ := nfct.NewConntrack()
defer ct.Destroy()
nlh, _ := mnl.NewNlmsgBytes(nlmsgbuf10)
ret, err := ct.NlmsgParse(nlh)
Expect(ret).To(Equal(0))
Expect(err).To(BeNil())
nlh, _ = mnl.NewNlmsg(1024)
nlh.Type = (NFNL_SUBSYS_CTNETLINK << 8) | IPCTNL_MSG_CT_DELETE
nlh.Flags = 0
nlh.Seq = 0
nlh.Pid = 0
nfh := (*Nfgenmsg)(nlh.PutExtraHeader(SizeofNfgenmsg))
nfh.Nfgen_family = AF_INET
nfh.Version = NFNETLINK_V0
nfh.Res_id = 0
ct.SetAttrU8(nfct.ATTR_ORIG_L3PROTO, 2)
ct.SetAttrU32(nfct.ATTR_ORIG_IPV4_SRC, 0x4030201)
ct.SetAttrU32(nfct.ATTR_ORIG_IPV4_DST, 0xfcfdfeff)
ct.SetAttrU16(nfct.ATTR_ORIG_L4PROTO, 17)
ct.SetAttrU16(nfct.ATTR_ORIG_PORT_SRC, 0x8ff8)
ct.SetAttrU16(nfct.ATTR_ORIG_PORT_DST, 0x3500)
ct.SetAttrU8(nfct.ATTR_REPL_L3PROTO, 2)
ct.SetAttrU32(nfct.ATTR_REPL_IPV4_SRC, 0xfcfdfeff)
ct.SetAttrU32(nfct.ATTR_REPL_IPV4_DST, 0x4030201)
ct.SetAttrU16(nfct.ATTR_REPL_L4PROTO, 17)
ct.SetAttrU16(nfct.ATTR_REPL_PORT_SRC, 0x3500)
ct.SetAttrU16(nfct.ATTR_REPL_PORT_DST, 0x8ff8)
ct.SetAttrU32(nfct.ATTR_STATUS, uint32(nfct.IPS_CONFIRMED))
ret, err = ct.NlmsgBuild(nlh)
Expect(err).To(BeNil())
Expect(ret).To(Equal(0))
b, _ := nlh.MarshalBinary()
Expect(b).To(Equal(nlmsgbuf11))
})
})
Context("Only create and add event filter", func() {
It("should create new filter", func() {
filter, err := nfct.NewFilter()
defer filter.Destroy()
Expect(err).To(BeNil())
})
It("should create new filter", func() {
filter, err := nfct.NewFilter()
defer filter.Destroy()
Expect(err).To(BeNil())
})
It("should add dump mark obj to event filter", func() {
filter, err := nfct.NewFilter()
defer filter.Destroy()
Expect(err).To(BeNil())
mark := nfct.FilterDumpMark{Val: 0x12345678, Mask: 0xffffffff}
err = filter.AddAttrPtr(nfct.NFCT_FILTER_MARK, &mark)
Expect(err).To(BeNil())
})
})
})