-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathnffile.h
2200 lines (1896 loc) · 78.7 KB
/
nffile.h
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
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag
* Copyright (c) 2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Author: haag $
*
* $Id: nffile.h 40 2009-12-16 10:41:44Z haag $
*
* $LastChangedRevision: 40 $
*
*/
#ifndef _NFFILE_H
#define _NFFILE_H 1
#ifdef HAVE_STDDEF_H
#include <stddef.h>
#endif
#define IDENTLEN 128
#define IDENTNONE "none"
#define NF_EOF 0
#define NF_ERROR -1
#define NF_CORRUPT -2
#define NF_DUMPFILE "nfcapd.current"
/*
* output buffer max size, before writing data to the file
* used to cache flows before writing to disk. size: tradeoff between
* size and time to flush to disk. Do not delay collector with long I/O
*/
#define WRITE_BUFFSIZE 1048576
/*
* use this buffer size to allocate memory for the output buffer
* data other than flow records, such as histograms, may be larger than
* WRITE_BUFFSIZE and have potentially more time to flush to disk
*/
#define BUFFSIZE (5*WRITE_BUFFSIZE)
/* if the output buffer reaches this limit, it gets flushed. This means,
* that 0.5MB input data may produce max 1MB data in output buffer, otherwise
* a buffer overflow may occur, and data does not get processed correctly.
* However, every Process_vx function checks buffer boundaries.
*/
/*
* nfdump binary file layout
* =========================
* Each data file starts with a file header, which identifies the file as an nfdump data file.
* The magic 16bit integer at the beginning of each file must read 0xA50C. This also guarantees
* that endian dependant files are read correct.
*
* Principal layout, recognized as LAYOUT_VERSION_1:
*
* +-----------+-------------+-------------+-------------+-----+-------------+
* |Fileheader | stat record | datablock 1 | datablock 2 | ... | datablock n |
* +-----------+-------------+-------------+-------------+-----+-------------+
*/
typedef struct file_header_s {
uint16_t magic; // magic to recognize nfdump file type and endian type
#define MAGIC 0xA50C
uint16_t version; // version of binary file layout, incl. magic
#define LAYOUT_VERSION_1 1
uint32_t flags;
#define NUM_FLAGS 3
#define FLAG_COMPRESSED 0x1 // flow records are compressed
#define FLAG_ANONYMIZED 0x2 // flow data are anonimized
#define FLAG_CATALOG 0x4 // has a file catalog record after stat record
/*
0x1 File is compressed with LZO1X-1 compression
*/
uint32_t NumBlocks; // number of data blocks in file
char ident[IDENTLEN]; // string identifier for this file
} file_header_t;
/*
* Compatible with nfdump x.x.x file format: After the file header an
* inplicit stat record follows, which contains the statistics
* information about all netflow records in this file.
*/
typedef struct stat_record_s {
// overall stat
uint64_t numflows;
uint64_t numbytes;
uint64_t numpackets;
// flow stat
uint64_t numflows_tcp;
uint64_t numflows_udp;
uint64_t numflows_icmp;
uint64_t numflows_other;
// bytes stat
uint64_t numbytes_tcp;
uint64_t numbytes_udp;
uint64_t numbytes_icmp;
uint64_t numbytes_other;
// packet stat
uint64_t numpackets_tcp;
uint64_t numpackets_udp;
uint64_t numpackets_icmp;
uint64_t numpackets_other;
// time window
uint32_t first_seen;
uint32_t last_seen;
uint16_t msec_first;
uint16_t msec_last;
// other
uint32_t sequence_failure;
} stat_record_t;
typedef struct stat_header_s {
uint16_t type; // stat record type
// compatible stat type nfdump 1.5.x in new extended stat record type
#define STD_STAT_TYPE 0
uint16_t size; // size of the stat record in bytes without this header
} stat_header_t;
// Netflow v9 field type/values
/*
*
* Block type 2:
* =============
* Each data block start with a common data block header, which specifies the size, type and the number of records
* in this data block
*/
typedef struct data_block_header_s {
uint32_t NumRecords; // number of data records in data block
uint32_t size; // size of this block in bytes without this header
uint16_t id; // Block ID == DATA_BLOCK_TYPE_2
uint16_t flags; // 0 - kompatibility
// 1 - block uncompressed
// 2 - block compressed
} data_block_header_t;
// compat nfdump 1.5.x data block type
#define DATA_BLOCK_TYPE_1 1
// nfdump 1.6.x data block type
#define DATA_BLOCK_TYPE_2 2
/*
*
* Block type 3
* ============
* same block header as type 2. Used for data other than flow data - e.g. histograms. Important difference:
* included data records have type L_record_header_t headers in order to allow larger data records.
*
*/
#define Large_BLOCK_Type 3
typedef struct L_record_header_s {
// record header
uint32_t type;
uint32_t size;
} L_record_header_t;
/*
*
* Catalog Block
* =============
* introduces a file catalog for nfdump files. Not yet really used in nfdump-1.6.x
* The catalog will get implemented later - most likely 1.7
* The flag FLAG_CATALOG is used to flag the file for having a catalog
*
*/
#define CATALOG_BLOCK 4
typedef struct catalog_s {
uint32_t NumRecords; // set to the number of catalog entries
uint32_t size; // sizeof(nffile_catalog_t) without this header (-12)
uint16_t id; // Block ID == CATALOG_BLOCK
uint16_t pad; // unused align 32 bit
off_t reserved; // reserved, set to 0;
// catalog data
struct catalog_entry_s {
uint32_t type; // what catalog type does the entry point to
// type = 0 reserved
#define EXPORTER_table 1
#define MAX_CATALOG_ENTRIES 16
off_t offset; // point to a data block with standard header data_block_header_t
} entries[MAX_CATALOG_ENTRIES]; // the number of types we currently have defined - may grow in future
} catalog_t;
/*
* Generic file handle for reading/writing files
* if a file is read only writeto and block_header are NULL
*/
typedef struct nffile_s {
file_header_t *file_header; // file header
data_block_header_t *block_header; // buffer
void *buff_ptr; // pointer into buffer for read/write blocks/records
stat_record_t *stat_record; // flow stat record
catalog_t *catalog; // file catalog
int _compress; // data compressed flag
int fd; // file descriptor
} nffile_t;
/*
* The new block type 2 introduces a changed common record and multiple extension records. This allows a more flexible data
* storage of netflow v9 records and 3rd party extension to nfdump.
*
* A block type 2 may contain different record types, as described below.
*
* Record description:
* -------------------
* A record always starts with a 16bit record id followed by a 16bit record size. This record size is the full size of this
* record incl. record type and size fields and all record extensions.
*
* Know record types:
* Type 0: reserved
* Type 1: Common netflow record incl. all record extensions
* Type 2: Extension map
* Type 3: xstat - port histogram record
* Type 4: xstat - bpp histogram record
*/
#define CommonRecordV0Type 1
#define ExtensionMapType 2
#define PortHistogramType 3
#define BppHistogramType 4
// TC code - phased out
#define ExporterRecordType 5
#define SamplerRecordype 6
// replaces TC Types
#define ExporterInfoRecordType 7
#define ExporterStatRecordType 8
#define SamplerInfoRecordype 9
// new extended Common Record as intermediate solution to overcome 255 exporters
// requires moderate changes till 1.7
#define CommonRecordType 10
/*
* All records are 32bit aligned and layouted in a 64bit array. The numbers placed in () refer to the netflow v9 type id.
*
* Record type 1
* =============
* The record type 1 describes a netflow data record incl. all optional extensions for this record.
* A netflow data record requires at least the first 3 extensions 1..3. All other extensions are optional
* and described in the extensiion map. The common record contains a reference to the extension map which
* applies for this record.
*
* flags:
* bit 0: 0: IPv4 1: IPv6
* bit 1: 0: 32bit dPkts 1: 64bit dPkts
* bit 2: 0: 32bit dOctets 1: 64bit dOctets
* bit 3: 0: IPv4 next hop 1: IPv6 next hop
* bit 4: 0: IPv4 BGP next hop 1: BGP IPv6 next hop
* bit 5: 0: IPv4 exporter IP 1: IPv6 exporter IP
* bit 6: 0: flow 1: event
* bit 7: 0: unsampled 1: sampled flow - sampling applied
*
* Required extensions: 1,2,3
* ------------------------------
* A netflow record consists at least of a common record ( extension 0 ) and 3 required extension:
*
* Extension 1: IPv4 or IPv4 src and dst addresses Flags bit 0: 0: IPv4, 1: IPv6
* Extension 2: 32 or 64 bit packet counter Flags bit 1: 0: 32bit, 1: 64bit
* Extension 3: 32 or 64 bit byte counter Flags bit 2: 0: 32bit, 1: 64bit
*
* Commmon record - extension 0
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | - | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | record type == 1 | size | flags | tag | ext. map |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 1 | msec_first | msec_last | first (22) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 2 | last (21) |fwd_status(89)| tcpflags (6) | proto (4) | src tos (5) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 3 | srcport (7) | dstport(11)/ICMP (32) |
* +----+--------------+--------------+--------------+--------------+
*
* Commmon record - extension 0 - Type 10
* required for larger exporter ID reference
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | - | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | record type == 10 | size | flags | ext. map |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 1 | msec_first | msec_last | first (22) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 2 | last (21) |fwd_status(89)| tcpflags (6) | proto (4) | src tos (5) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 3 | srcport (7) | dstport(11)/ICMP (32) | exporter ID | <free> |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
*
*/
#define COMMON_BLOCK_ID 0
typedef struct record_header_s {
// record header
uint16_t type;
uint16_t size;
} record_header_t;
typedef struct common_record_s {
// record head
uint16_t type;
uint16_t size;
// record meta data
uint16_t flags;
#define FLAG_IPV6_ADDR 1
#define FLAG_PKG_64 2
#define FLAG_BYTES_64 4
#define FLAG_IPV6_NH 8
#define FLAG_IPV6_NHB 16
#define FLAG_IPV6_EXP 32
#define FLAG_EVENT 64
#define FLAG_SAMPLED 128
#define SetFlag(var, flag) (var |= flag)
#define ClearFlag(var, flag) (var &= ~flag)
#define TestFlag(var, flag) (var & flag)
uint16_t ext_map;
// netflow common record
uint16_t msec_first;
uint16_t msec_last;
uint32_t first;
uint32_t last;
uint8_t fwd_status;
uint8_t tcp_flags;
uint8_t prot;
uint8_t tos;
uint16_t srcport;
uint16_t dstport;
uint16_t exporter_sysid;
uint16_t reserved;
// link to extensions
uint32_t data[1];
} common_record_t;
typedef struct common_record_v0_s {
// record head
uint16_t type;
uint16_t size;
// record meta data
uint8_t flags;
uint8_t exporter_sysid;
uint16_t ext_map;
// netflow common record
uint16_t msec_first;
uint16_t msec_last;
uint32_t first;
uint32_t last;
uint8_t fwd_status;
uint8_t tcp_flags;
uint8_t prot;
uint8_t tos;
uint16_t srcport;
uint16_t dstport;
// link to extensions
uint32_t data[1];
} common_record_v0_t;
#define COMMON_RECORD_DATA_SIZE (sizeof(common_record_t) - sizeof(uint32_t) )
#define COMMON_RECORDV0_DATA_SIZE (sizeof(common_record_v0_t) - sizeof(uint32_t) )
#define COMMON_BLOCK 0
/*
* Required extensions:
* --------------------
* Extension 1:
* IPv4/v6 address type
* IP version: IPv4
* |
* Flags: xxxx xxx0
* IPv4:
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | srcip (8) | dstip (12) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
*
* IPv6:
* IP version: IPv6
* |
* Flags: xxxx xxx1
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | srcip (27) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 1 | srcip (27) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 2 | dstip (28) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 3 | dstip (28) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
*
*/
#define EX_IPv4v6 1
typedef struct ipv4_block_s {
uint32_t srcaddr;
uint32_t dstaddr;
uint8_t data[4]; // .. more data below
} ipv4_block_t;
typedef struct ipv6_block_s {
uint64_t srcaddr[2];
uint64_t dstaddr[2];
uint8_t data[4]; // .. more data below
} ipv6_block_t;
// single IP addr for next hop and bgp next hop
typedef struct ip_addr_s {
union {
struct {
#ifdef WORDS_BIGENDIAN
uint32_t fill[3];
uint32_t _v4;
#else
uint32_t fill1[2];
uint32_t _v4;
uint32_t fill2;
#endif
};
uint64_t _v6[2];
} ip_union;
} ip_addr_t;
#define v4 ip_union._v4
#define v6 ip_union._v6
/*
* Extension 2:
* In packet counter size
*
* In packet counter size 4byte
* |
* Flags: xxxx xx0x
* +---++--------------+--------------+--------------+--------------+
* | 0 | in pkts (2) |
* +---++--------------+--------------+--------------+--------------+
*
* In packet counter size 8byte
* |
* Flags: xxxx xx1x
* +---++--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | in pkts (2) |
* +---++--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
*
*/
#define EX_PACKET_4_8 2
typedef struct value32_s {
uint32_t val;
uint8_t data[4]; // .. more data below
} value32_t;
typedef struct value64_s {
union val_s {
uint64_t val64;
uint32_t val32[2];
} val;
uint8_t data[4]; // .. more data below
} value64_t;
/* Extension 3:
* in byte counter size
* In byte counter size 4byte
* |
* Flags: xxxx x0xx
*
* +---++--------------+--------------+--------------+--------------+
* | 0 | in bytes (1) |
* +---++--------------+--------------+--------------+--------------+
*
* In byte counter size 8byte
* |
* Flags: xxxx x1xx
* +---++--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | in bytes (1) |
* +---++--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
*/
#define EX_BYTE_4_8 3
/*
*
* Optional extension:
* ===================
*
* Interface record
* ----------------
* Interface records are optional and accepted as either 2 or 4 bytes numbers
* Extension 4:
* +---++--------------+--------------+--------------+--------------+
* | 0 | input (10) | output (14) |
* +---++--------------+--------------+--------------+--------------+
*/
#define EX_IO_SNMP_2 4
typedef struct tpl_ext_4_s {
uint16_t input;
uint16_t output;
uint8_t data[4]; // points to further data
} tpl_ext_4_t;
/*
* Extension 5:
* +---++--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | input (10) | output (14) |
* +---++--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* Extension 4 and 5 are mutually exclusive in the extension map
*/
#define EX_IO_SNMP_4 5
typedef struct tpl_ext_5_s {
uint32_t input;
uint32_t output;
uint8_t data[4]; // points to further data
} tpl_ext_5_t;
/*
* AS record
* ---------
* AS records are optional and accepted as either 2 or 4 bytes numbers
* Extension 6:
* +---++--------------+--------------+--------------+--------------+
* | 0 | src as (16) | dst as (17) |
* +---++--------------+--------------+--------------+--------------+
*/
#define EX_AS_2 6
typedef struct tpl_ext_6_s {
uint16_t src_as;
uint16_t dst_as;
uint8_t data[4]; // points to further data
} tpl_ext_6_t;
/*
* Extension 7:
* +---++--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | src as (16) | dst as (17) |
* +---++--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* Extension 6 and 7 are mutually exclusive in the extension map
*/
#define EX_AS_4 7
typedef struct tpl_ext_7_s {
uint32_t src_as;
uint32_t dst_as;
uint8_t data[4]; // points to further data
} tpl_ext_7_t;
/*
* Multiple fields record
* ----------------------
* These 4 different fields are grouped together in a 32bit value.
* Extension 8:
* +---++--------------+--------------+--------------+--------------+
* | 3 | dst tos(55) | dir(61) | srcmask(9,29)|dstmask(13,30)|
* +---++--------------+--------------+--------------+--------------+
*/
#define EX_MULIPLE 8
typedef struct tpl_ext_8_s {
union {
struct {
uint8_t dst_tos;
uint8_t dir;
uint8_t src_mask;
uint8_t dst_mask;
};
uint32_t any;
};
uint8_t data[4]; // points to further data
} tpl_ext_8_t;
/*
* IP next hop
* -------------
* IPv4:
* Extension 9:
* IP version: IPv6
* |
* Flags: xxxx 0xxx
* +----+--------------+--------------+--------------+--------------+
* | 0 | next hop ip (15) |
* +----+--------------+--------------+--------------+--------------+
*/
#define EX_NEXT_HOP_v4 9
typedef struct tpl_ext_9_s {
uint32_t nexthop;
uint8_t data[4]; // points to further data
} tpl_ext_9_t;
/*
* IPv6:
* Extension 10:
* IP version: IPv6
* |
* Flags: xxxx 1xxx
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | next hop ip (62) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 1 | next hop ip (62) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* Extension 9 and 10 are mutually exclusive in the extension map
*/
#define EX_NEXT_HOP_v6 10
typedef struct tpl_ext_10_s {
uint64_t nexthop[2];
uint8_t data[4]; // points to further data
} tpl_ext_10_t;
/*
* BGP next hop IP
* ------------------
* IPv4:
* Extension 11:
* IP version: IPv6
* |
* Flags: xxx0 xxxx
* +----+--------------+--------------+--------------+--------------+
* | 0 | bgp next ip (18) |
* +----+--------------+--------------+--------------+--------------+
*/
#define EX_NEXT_HOP_BGP_v4 11
typedef struct tpl_ext_11_s {
uint32_t bgp_nexthop;
uint8_t data[4]; // points to further data
} tpl_ext_11_t;
/*
* IPv6:
* Extension 12:
* IP version: IPv6
* |
* Flags: xxx1 xxxx
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | bgp next ip (63) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 1 | bgp next ip (63) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
*/
#define EX_NEXT_HOP_BGP_v6 12
typedef struct tpl_ext_12_s {
uint64_t bgp_nexthop[2];
uint8_t data[4]; // points to further data
} tpl_ext_12_t;
/*
* VLAN record
* -----------
* Extension 13:
* +----+--------------+--------------+--------------+--------------+
* | 0 | src vlan(58) | dst vlan (59) |
* +----+--------------+--------------+--------------+--------------+
*/
#define EX_VLAN 13
typedef struct tpl_ext_13_s {
uint16_t src_vlan;
uint16_t dst_vlan;
uint8_t data[4]; // points to further data
} tpl_ext_13_t;
/*
* Out packet counter size
* ------------------------
* 4 byte
* Extension 14:
* +----+--------------+--------------+--------------+--------------+
* | 0 | out pkts (24) |
* +----+--------------+--------------+--------------+--------------+
*/
#define EX_OUT_PKG_4 14
typedef struct tpl_ext_14_s {
uint32_t out_pkts;
uint8_t data[4]; // points to further data
} tpl_ext_14_t;
/*
* 4 byte
* Extension 15:
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | out pkts (24) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* Extension 14 and 15 are mutually exclusive in the extension map
*/
#define EX_OUT_PKG_8 15
typedef struct tpl_ext_15_s {
union {
uint64_t out_pkts;
uint32_t v[2]; // for strict alignment use 2x32bits
};
uint8_t data[4]; // points to further data
} tpl_ext_15_t;
/*
* Out byte counter size
* ---------------------
* 4 byte
* Extension 16:
* +----+--------------+--------------+--------------+--------------+
* | 0 | out bytes (23) |
* +----+--------------+--------------+--------------+--------------+
*/
#define EX_OUT_BYTES_4 16
typedef struct tpl_ext_16_s {
uint32_t out_bytes;
uint8_t data[4]; // points to further data
} tpl_ext_16_t;
/* 8 byte
* Extension 17:
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | out bytes (23) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* Extension 16 and 17 are mutually exclusive in the extension map
*/
#define EX_OUT_BYTES_8 17
typedef struct tpl_ext_17_s {
union {
uint64_t out_bytes;
uint32_t v[2]; // potential 32bit alignment
};
uint8_t data[4]; // points to further data
} tpl_ext_17_t;
/*
* Aggr flows
* ----------
* 4 byte
* Extension 18:
* +----+--------------+--------------+--------------+--------------+
* | 0 | aggr flows (3) |
* +----+--------------+--------------+--------------+--------------+
*/
#define EX_AGGR_FLOWS_4 18
typedef struct tpl_ext_18_s {
uint32_t aggr_flows;
uint8_t data[4]; // points to further data
} tpl_ext_18_t;
/* 8 byte
* Extension 19:
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | aggr flows (3) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* Extension 18 and 19 are mutually exclusive in the extension map
*/
#define EX_AGGR_FLOWS_8 19
typedef struct tpl_ext_19_s {
union {
uint64_t aggr_flows;
uint32_t v[2]; // 32bit alignment
};
uint8_t data[4]; // points to further data
} tpl_ext_19_t;
/* 16 byte
* Extension 20:
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | 0 | in src mac (56) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 1 | 0 | out dst mac (57) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
*/
#define EX_MAC_1 20
typedef struct tpl_ext_20_s {
union {
uint64_t in_src_mac;
uint32_t v1[2];
};
union {
uint64_t out_dst_mac;
uint32_t v2[2];
};
uint8_t data[4]; // points to further data
} tpl_ext_20_t;
/* 16 byte
* Extension 21:
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | 0 | in dst mac (80) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 1 | 0 | out src mac (81) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
*/
#define EX_MAC_2 21
typedef struct tpl_ext_21_s {
union {
uint64_t in_dst_mac;
uint32_t v1[2];
};
union {
uint64_t out_src_mac;
uint32_t v2[2];
};
uint8_t data[4]; // points to further data
} tpl_ext_21_t;
/* 40 byte
* Extension 22:
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | 0 | MPLS_LABEL_2 (71) | 0 | MPLS_LABEL_1 (70) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 1 | 0 | MPLS_LABEL_4 (73) | 0 | MPLS_LABEL_3 (72) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 2 | 0 | MPLS_LABEL_6 (75) | 0 | MPLS_LABEL_5 (74) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 3 | 0 | MPLS_LABEL_8 (77) | 0 | MPLS_LABEL_7 (76) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 3 | 0 | MPLS_LABEL_10 (79) | 0 | MPLS_LABEL_9 (78) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
*/
#define EX_MPLS 22
typedef struct tpl_ext_22_s {
uint32_t mpls_label[10];
uint8_t data[4]; // points to further data
} tpl_ext_22_t;
/*
* Sending router IP
* -----------------
* IPv4:
* Extension 23:
* IP version: IPv6
* |
* Flags: xx0x xxxx
* +----+--------------+--------------+--------------+--------------+
* | 0 | router ipv4 () |
* +----+--------------+--------------+--------------+--------------+
*/
#define EX_ROUTER_IP_v4 23
typedef struct tpl_ext_23_s {
uint32_t router_ip;
uint8_t data[4]; // points to further data
} tpl_ext_23_t;
/*
* IPv6:
* Extension 24:
* IP version: IPv6
* |
* Flags: xx1x xxxx
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | router ip v6 () |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 1 | router ip v6 () |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* Extension 23 and 24 are mutually exclusive in the extension map
*/
#define EX_ROUTER_IP_v6 24
typedef struct tpl_ext_24_s {
uint64_t router_ip[2];
uint8_t data[4]; // points to further data
} tpl_ext_24_t;
/*
* router source ID
* ----------------
* For v5 netflow, it's engine type/engine ID
* for v9 it's the source_id
* Extension 25:
* +----+--------------+--------------+--------------+--------------+
* | 0 | fill |engine tpe(38)|engine ID(39) |
* +----+--------------+--------------+--------------+--------------+
*/
#define EX_ROUTER_ID 25
typedef struct tpl_ext_25_s {
uint16_t fill;
uint8_t engine_type;
uint8_t engine_id;
uint8_t data[4]; // points to further data
} tpl_ext_25_t;
/*
* BGP prev/next adjacent AS
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | bgpNextAdjacentAsNumber(128) | bgpPrevAdjacentAsNumber(129) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
*/
#define EX_BGPADJ 26
typedef struct tpl_ext_26_s {
uint32_t bgpNextAdjacentAS;
uint32_t bgpPrevAdjacentAS;
uint8_t data[4]; // points to further data
} tpl_ext_26_t;
/*
* time flow received in ms
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | T received() |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
*/
#define EX_RECEIVED 27
typedef struct tpl_ext_27_s {
union {
uint64_t received;
uint32_t v[2];
};
uint8_t data[4]; // points to further data
} tpl_ext_27_t;
#define EX_RESERVED_1 28
#define EX_RESERVED_2 29
#define EX_RESERVED_3 30
#define EX_RESERVED_4 31
#define EX_RESERVED_5 32
#define EX_RESERVED_6 33
#define EX_RESERVED_7 34
#define EX_RESERVED_8 35
#define EX_RESERVED_9 36
/*
* NSEL Common block
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 0 | NF_F_FLOW_CREATE_TIME_MSEC(152) |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 1 | NF_F_CONN_ID(148) |i type(176/8) |i code(177/9) |EVT(40005/233)| fill |
* +----+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
* | 2 | NF_F_FW_EXT_EVENT(33002) | fill2 |
* +----+--------------+--------------+--------------+--------------+
* * EVT: NF_F_FW_EVENT
* * XEVT: NF_F_FW_EXT_EVENT
*/
#define EX_NSEL_COMMON 37
typedef struct tpl_ext_37_s {
uint64_t event_time;
uint32_t conn_id;
union {
struct {
#ifdef WORDS_BIGENDIAN
uint8_t icmp_type;
uint8_t icmp_code;
#else
uint8_t icmp_code;
uint8_t icmp_type;
#endif
};
uint16_t nsel_icmp;
};
uint8_t fw_event;
uint8_t fill;
uint16_t fw_xevent;