1 /* 2 ** Copyright (C) 2001-2020 by Carnegie Mellon University. 3 ** 4 ** @OPENSOURCE_LICENSE_START@ 5 ** See license information in ../../LICENSE.txt 6 ** @OPENSOURCE_LICENSE_END@ 7 */ 8 #ifndef _SILK_FILES_H 9 #define _SILK_FILES_H 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 #include <silk/silk.h> 15 16 RCSIDENTVAR(rcsID_SILK_FILES_H, "$SiLK: silk_files.h ef14e54179be 2020-04-14 21:57:45Z mthomas $"); 17 18 #include <silk/silk_types.h> 19 20 21 /*** Compression Methods ***********************************************/ 22 23 /* 24 * The compression method (compmethod) is used to compress the data 25 * section of a SiLK binary file. 26 * 27 * SiLK is able to support the following compmethods. In order for 28 * a compression method to be supported, the library and header 29 * file must have been available at the time SiLK was compiled. 30 * 31 * SiLK cannot read a file if the file uses a compression method 32 * that is not available in this build of SiLK. 33 * 34 * The --version switch on most SiLK applications shows what set of 35 * compression methods are available in this SiLK installation. 36 * 37 * Keep the following set of constants in sync with the 38 * sk_compmethod_names[] array defined below. 39 */ 40 41 /** 42 * Do not use any compression. 43 */ 44 #define SK_COMPMETHOD_NONE 0 45 46 /** 47 * Use zlib compression (like that used by gzip). 48 */ 49 #define SK_COMPMETHOD_ZLIB 1 50 51 /** 52 * Use the lzo1x algorithm from LZO real-time compression library. 53 */ 54 #define SK_COMPMETHOD_LZO1X 2 55 56 /** 57 * Use Snappy compression. Since SiLK 3.13.0.. 58 */ 59 #define SK_COMPMETHOD_SNAPPY 3 60 61 #ifdef SKCOMPMETHOD_SOURCE 62 static const char *sk_compmethod_names[] = { 63 "none", 64 "zlib", 65 "lzo1x", 66 "snappy", 67 "" 68 }; 69 #endif /* SKCOMPMETHOD_SOURCE */ 70 71 /* 72 * Special compression method values also exit. 73 */ 74 75 /** 76 * Use the default compression method that was specified when SiLK 77 * was compiled. 78 */ 79 #define SK_COMPMETHOD_DEFAULT 255 80 81 /** 82 * Use the "best" compression method. This is lzo1x if available, 83 * else snappy if available, else zlib if available, else none. 84 */ 85 #define SK_COMPMETHOD_BEST 254 86 87 88 /* 89 * Values returned by skCompMethodCheck() 90 */ 91 92 /** 93 * skCompMethodCheck() returns this value when the compression 94 * method is a known value and the method's library is available. 95 */ 96 #define SK_COMPMETHOD_IS_AVAIL 6 97 98 /** 99 * skCompMethodCheck() returns this value when the compression 100 * method is a known value but the method relies on an external 101 * library that is not part of this build of SiLK. 102 */ 103 #define SK_COMPMETHOD_IS_VALID 2 104 105 /** 106 * skCompMethodCheck() returns this value when the compression 107 * method is either SK_COMPMETHOD_DEFAULT or SK_COMPMETHOD_BEST. 108 */ 109 #define SK_COMPMETHOD_IS_KNOWN 1 110 111 /** 112 * Check whether a compression method is valid and/or available. 113 * 114 * If the compression method 'comp_method' is completely 115 * unrecognized, return 0. 116 * 117 * Return SK_COMPMETHOD_IS_KNOWN when 'comp_method' is an 118 * "undecided" value (i.e., SK_COMPMETHOD_DEFAULT or 119 * SK_COMPMETHOD_BEST). These compression methods should be 120 * considered valid for writing, as they will be converted to an 121 * appropriate type once the stream they are connected to is 122 * opened. 123 * 124 * Return SK_COMPMETHOD_IS_VALID when 'comp_method' contains a 125 * known value other than an "undecided" value, but the compression 126 * method relies on an external library that is not part of this 127 * build of SiLK. 128 * 129 * Return SK_COMPMETHOD_IS_AVAIL when 'comp_method' is a known 130 * value whose library is available. These compression methods are 131 * valid for reading or for writing. 132 * 133 * To determine whether 'comp_method' is valid for read, mask the 134 * output by 4. To determine whether 'comp_method' is valid for 135 * write, mask the output of this function by 5. To determine 136 * whether 'comp_method' is an actual compression method (that is, 137 * not an "undecided" value), mask the output by 2. 138 * 139 * Replaces sksiteCompmethodCheck(). Since SiLK 3.13.0. 140 */ 141 int 142 skCompMethodCheck( 143 sk_compmethod_t comp_method); 144 145 /** 146 * Return the generically "best" compression method from all those 147 * that are available. 148 * 149 * Replaces sksiteCompmethodGetBest(). Since SiLK 3.13.0. 150 */ 151 sk_compmethod_t 152 skCompMethodGetBest( 153 void); 154 155 /** 156 * Return the default compression method. 157 * 158 * Replaces sksiteCompmethodGetDefault(). Since SiLK 3.13.0. 159 */ 160 sk_compmethod_t 161 skCompMethodGetDefault( 162 void); 163 164 /** 165 * Given the compress method 'comp_method', write the name of that 166 * method into 'out_buffer' whose length is 'bufsize'. The 167 * function returns a pointer to 'out_buffer', or NULL for an 168 * invalid compression method. 169 * 170 * Replaces sksiteCompmethodGetName(). Since SiLK 3.13.0. 171 */ 172 int 173 skCompMethodGetName( 174 char *buffer, 175 size_t buffer_size, 176 sk_compmethod_t comp_method); 177 178 /** 179 * Set the default compression method to 'comp_method', overriding 180 * the default value specified when SiLK was compiled. Return 0 on 181 * success, -1 if the method is not available. 182 * 183 * To change the default returned by the --compression-method 184 * switch, call this function prior to calling 185 * skCompMethodOptionsRegister(). 186 * 187 * Replaces sksiteCompmethodSetDefault(). Since SiLK 3.13.0. 188 */ 189 int 190 skCompMethodSetDefault( 191 sk_compmethod_t comp_method); 192 193 /** 194 * Do not check the SILK_COMPRESSION_METHOD environment variable 195 * when initializing the compression method variable passed into 196 * skCompMethodOptionsRegister(). 197 * 198 * Since SiLK 3.13.0. 199 */ 200 void 201 skCompMethodOptionsNoEnviron( 202 void); 203 204 /** 205 * Add a command-line switch that allows the user to set the 206 * compression method of binary output files. After 207 * skOptionsParse() sucessfully returns, the referent of 208 * 'compression_method' contains the compression method to use. 209 * 210 * When this function is called, the SILK_COMPRESSION_METHOD 211 * environment variable is normally checked for a compression 212 * method, and if the variable specifies an available method, the 213 * referent of 'compression_method' is set to that value. To 214 * suppress this check of the environment, call 215 * skCompMethodOptionsNoEnviron() prior to calling this function. 216 * 217 * This function initializes the referent of 'compression_method' 218 * to the compression method in SILK_COMPRESSION_METHOD envar or 219 * the default compression method specified when SiLK was compiled. 220 * To modify the default value used by an application, call 221 * skCompMethodSetDefault() prior to calling this function. 222 * 223 * Replaces sksiteCompmethodOptionsRegister(). Since SiLK 3.13.0. 224 */ 225 int 226 skCompMethodOptionsRegister( 227 sk_compmethod_t *compression_method); 228 229 /** 230 * Print the usage for the compression-method option to the file 231 * handle 'fh'. 232 * 233 * Replaces sksiteCompmethodOptionsUsage(). Since SiLK 3.13.0. 234 */ 235 void 236 skCompMethodOptionsUsage( 237 FILE *fh); 238 239 240 241 /** File Formats ******************************************************/ 242 243 /** 244 * Copy the name of the file format with the ID 'format_id' into 245 * 'buffer' whose size is 'buffer_size'. 246 * 247 * If the name is longer than buffer_size, the value returned is 248 * truncated with a '\0' in the final position. 249 * 250 * Return the number of characters that would have been written if 251 * the buffer had been long enough. This length does not include 252 * the trailing '\0'. 253 * 254 * Replaces sksiteFileformatGetName(). Since SiLK 3.13.0. 255 */ 256 int 257 skFileFormatGetName( 258 char *buffer, 259 size_t buffer_size, 260 sk_file_format_t format_id); 261 262 /** 263 * Return 1 if 'format_id' is a valid file output format or 0 if 264 * it is not. 265 * 266 * Replaces sksiteFileformatIsValid(). Since SiLK 3.13.0. 267 */ 268 int 269 skFileFormatIsValid( 270 sk_file_format_t format_id); 271 272 /** 273 * Return the file output format associated with the name. If the 274 * name is unknown, return SK_INVALID_FILE_FORMAT (whose value is 275 * defined in silk_types.h). 276 * 277 * Replaces sksiteFileformatFromName(). Since SiLK 3.13.0. 278 */ 279 sk_file_format_t 280 skFileFormatFromName( 281 const char *name); 282 283 284 /* define various output file formats here that we write to disk */ 285 286 #define FT_TCPDUMP 0x00 287 #define FT_GRAPH 0x01 288 #define FT_ADDRESSES 0x02 /* old address array used by addrtype */ 289 #define FT_PORTMAP 0x03 290 #define FT_SERVICEMAP 0x04 291 #define FT_NIDSMAP 0x05 292 #define FT_EXPERIMENT1 0x06 /* free for all ID */ 293 #define FT_EXPERIMENT2 0x07 /* free for all ID */ 294 #define FT_TEMPFILE 0x08 295 #define FT_AGGREGATEBAG 0x09 296 #define FT_IPFIX 0x0A 297 #define FT_RWIPV6 0x0B 298 #define FT_RWIPV6ROUTING 0x0C 299 #define FT_RWAUGSNMPOUT 0x0D 300 #define FT_RWAUGROUTING 0x0E 301 #define FT_RESERVED_0F 0x0F 302 #define FT_RWROUTED 0X10 303 #define FT_RWNOTROUTED 0X11 304 #define FT_RWSPLIT 0X12 305 #define FT_RWFILTER 0X13 306 #define FT_RWAUGMENTED 0X14 307 #define FT_RWAUGWEB 0X15 308 #define FT_RWGENERIC 0x16 309 #define FT_RESERVED_17 0x17 310 #define FT_RWDAILY 0x18 311 #define FT_RWSCAN 0x19 312 #define FT_RWACL 0x1A 313 #define FT_RWCOUNT 0x1B 314 #define FT_FLOWCAP 0x1C 315 #define FT_IPSET 0x1D 316 #define FT_TAGTREE 0x1E 317 #define FT_RWWWW 0x1F 318 #define FT_SHUFFLE 0x20 319 #define FT_RWBAG 0x21 320 #define FT_BLOOM 0x22 321 #define FT_RWPRINTSTATS 0x23 322 #define FT_PDUFLOWCAP 0x24 323 #define FT_PREFIXMAP 0x25 324 /* When you add new types here; add the name to the array below. */ 325 326 /* old identifier names */ 327 #define FT_IPTREE FT_IPSET 328 #define FT_MACROBAGTREE FT_RWBAG 329 330 331 /* 332 * This header is included by skfileformat.c after declaring 333 * SKFILEFORMAT_SOURCE. Users should use the functions defined 334 * above to access these strings values. 335 */ 336 337 #ifdef SKFILEFORMAT_SOURCE 338 static const char *sk_file_format_names[] = { 339 /* 0x00 */ "FT_TCPDUMP", 340 /* 0x01 */ "FT_GRAPH", 341 /* 0x02 */ "FT_ADDRESSES", 342 /* 0x03 */ "FT_PORTMAP", 343 /* 0x04 */ "FT_SERVICEMAP", 344 /* 0x05 */ "FT_NIDSMAP", 345 /* 0x06 */ "FT_EXPERIMENT1", 346 /* 0x07 */ "FT_EXPERIMENT2", 347 /* 0x08 */ "FT_TEMPFILE", 348 /* 0x09 */ "FT_AGGREGATEBAG", 349 /* 0x0A */ "FT_IPFIX", 350 /* 0x0B */ "FT_RWIPV6", 351 /* 0x0C */ "FT_RWIPV6ROUTING", 352 /* 0x0D */ "FT_RWAUGSNMPOUT", 353 /* 0x0E */ "FT_RWAUGROUTING", 354 /* 0x0F */ "FT_RESERVED_0F", 355 /* 0X10 */ "FT_RWROUTED", 356 /* 0X11 */ "FT_RWNOTROUTED", 357 /* 0X12 */ "FT_RWSPLIT", 358 /* 0X13 */ "FT_RWFILTER", 359 /* 0X14 */ "FT_RWAUGMENTED", 360 /* 0X15 */ "FT_RWAUGWEB", 361 /* 0x16 */ "FT_RWGENERIC", 362 /* 0x17 */ "FT_RESERVED_17", 363 /* 0x18 */ "FT_RWDAILY", 364 /* 0x19 */ "FT_RWSCAN", 365 /* 0x1A */ "FT_RWACL", 366 /* 0x1B */ "FT_RWCOUNT", 367 /* 0x1C */ "FT_FLOWCAP", 368 /* 0x1D */ "FT_IPSET", 369 /* 0x1E */ "FT_TAGTREE", 370 /* 0x1F */ "FT_RWWWW", 371 /* 0x20 */ "FT_SHUFFLE", 372 /* 0x21 */ "FT_RWBAG", 373 /* 0x22 */ "FT_BLOOM", 374 /* 0x23 */ "FT_RWPRINTSTATS", 375 /* 0x24 */ "FT_PDUFLOWCAP", 376 /* 0x25 */ "FT_PREFIXMAP", 377 "" 378 }; 379 #endif /* SKFILEFORMAT_SOURCE */ 380 381 #ifdef __cplusplus 382 } 383 #endif 384 #endif /* _SILK_FILES_H */ 385 386 /* 387 ** Local Variables: 388 ** mode:c 389 ** indent-tabs-mode:nil 390 ** c-basic-offset:4 391 ** End: 392 */ 393