1 /*
2  *  Copyright (c) 2020, Peter Haag
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *
8  *   * Redistributions of source code must retain the above copyright notice,
9  *     this list of conditions and the following disclaimer.
10  *   * Redistributions in binary form must reproduce the above copyright notice,
11  *     this list of conditions and the following disclaimer in the documentation
12  *     and/or other materials provided with the distribution.
13  *   * Neither the name of the author nor the names of its contributors may be
14  *     used to endorse or promote products derived from this software without
15  *     specific prior written permission.
16  *
17  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  *  POSSIBILITY OF SUCH DAMAGE.
28  *
29  */
30 
31 #ifndef _NFFILEV2_H
32 #define _NFFILEV2_H 1
33 
34 #include "config.h"
35 
36 #include <stddef.h>
37 #include <sys/types.h>
38 #ifdef HAVE_STDINT_H
39 #include <stdint.h>
40 #endif
41 
42 /*
43  * nfdump binary file layout 2
44  * ===========================
45  * Each data file starts with a file header, which identifies the file as an nfdump data file.
46  * The magic 16bit integer at the beginning of each file must read 0xA50C. This also guarantees
47  * that endian dependant files are read correct.
48  *
49  * Principal layout, recognized as LAYOUT_VERSION_2:
50  *
51  *   +-----------+-------------+-------------+-------------+-----+-------------+
52  *   |Fileheader | datablock 0 | datablock 1 | datablock 2 | ... | datablock n |
53  *   +-----------+-------------+-------------+-------------+-----+-------------+
54  */
55 
56 
57 typedef struct fileHeaderV2_s {
58 	uint16_t	magic;				// magic to recognize nfdump file type and endian type
59 #define MAGIC 0xA50C
60 
61 	uint16_t	version;			// version of binary file layout
62 #define LAYOUT_VERSION_2	2
63 
64 	uint32_t	nfversion;			// version of nfdump created this file
65 									// 4bytes 1.6.19-1 0x01061301
66 	time_t		created;			// file create time
67 
68 	uint8_t		compression;
69 #define NOT_COMPRESSED 0
70 #define LZO_COMPRESSED 1
71 #define BZ2_COMPRESSED 2
72 #define LZ4_COMPRESSED 3
73 	uint8_t		encryption;
74 	uint16_t	flags;
75 	uint32_t	unused;				// unused 0	- reserved for futur use
76 	uint64_t	unused2;			// unused 0 - reserved for futur use
77 
78 	uint32_t	BlockSize;			// max block size of data blocks
79 	uint32_t	NumBlocks;			// number of data blocks in file
80 } fileHeaderV2_t;
81 
82 
83 /*
84  *
85  * Generic data block
86  * ==================
87  * Data blocks are generic containers for the any type of data records.
88  * Each data block starts with a block header, which specifies the size, the number of records
89  * and data block properties. The struct is compatible with type 2 data records
90  */
91 
92 typedef struct dataBlock_s {
93 	uint32_t	type;			// Block type
94 #define TYPE_STAT_BLOCK 1
95 #define TYPE_RECORD_BLOCK 2
96 	uint32_t	size;			// size of this block in bytes without this header
97 } dataBlock_t;
98 
99 /*
100  * Generic data record
101  * Contains any type of data, specified by type
102  */
103 typedef struct recordHeader_s {
104  	// record header
105  	uint16_t	type;
106  	uint16_t	size;
107 } recordHeader_t;
108 
109 
110 #endif //_NFFILEV2_H
111 
112