Skip to content

Commit 831a0f1

Browse files
committed
unirec: skelet, ready for (re)implementation
1 parent fcd3be8 commit 831a0f1

File tree

7 files changed

+264
-172
lines changed

7 files changed

+264
-172
lines changed

extra_plugins/output/unirec/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ include_directories(
4848
add_library(unirec-output MODULE
4949
configuration.c
5050
configuration.h
51-
lnfstore.h
52-
unirecstore.c
51+
unirecplugin.h
52+
unirecplugin.c
5353
translator.c
5454
translator.h
5555
)

extra_plugins/output/unirec/configuration.c

Lines changed: 95 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* \file configuration.c
3-
* \author Lukas Hutak <[email protected]>
3+
* \author Tomas Cejka <[email protected]>
4+
* \author Jaroslav Hlavac <[email protected]>
45
* \brief Configuration parser (source file)
56
*/
67

@@ -39,7 +40,7 @@
3940
*/
4041

4142
#include "configuration.h"
42-
#include "lnfstore.h"
43+
#include "unirecplugin.h"
4344

4445
#include <stdlib.h>
4546
#include <inttypes.h>
@@ -130,44 +131,44 @@ configuration_validate(ipx_ctx_t *ctx, const struct conf_params *cfg)
130131
{
131132
int ret_code = IPX_OK;
132133

133-
if (!cfg->profiles.en && !cfg->files.path) {
134-
IPX_CTX_ERROR(ctx, "Storage path is not set.", '\0');
135-
ret_code = IPX_ERR_FORMAT;
136-
}
137-
138-
if (!cfg->files.suffix) {
139-
IPX_CTX_ERROR(ctx, "File suffix is not set.", '\0');
140-
ret_code = IPX_ERR_FORMAT;
141-
}
142-
143-
if (!cfg->file_lnf.prefix) {
144-
IPX_CTX_ERROR(ctx, "LNF file prefix is not set.", '\0');
145-
ret_code = IPX_ERR_FORMAT;
146-
}
147-
148-
if (cfg->file_index.en) {
149-
if (!cfg->file_index.prefix) {
150-
IPX_CTX_ERROR(ctx, "Index file prefix is not set.", '\0');
151-
ret_code = IPX_ERR_FORMAT;
152-
}
153-
154-
if (cfg->file_index.est_cnt == 0) {
155-
IPX_CTX_ERROR(ctx, "Estimated item count in Bloom Filter Index must be greater "
156-
"than 0.", '\0');
157-
ret_code = IPX_ERR_FORMAT;
158-
}
159-
160-
// Check output prefixes
161-
if (strcmp(cfg->file_index.prefix, cfg->file_lnf.prefix) == 0) {
162-
IPX_CTX_ERROR(ctx, "The same file prefix for LNF and Index file is not allowed");
163-
ret_code = IPX_ERR_FORMAT;
164-
}
165-
}
166-
167-
if (cfg->window.size == 0) {
168-
IPX_CTX_ERROR(ctx, "Window size must be greater than 0.", '\0');
169-
ret_code = IPX_ERR_FORMAT;
170-
}
134+
//if (!cfg->profiles.en && !cfg->files.path) {
135+
// IPX_CTX_ERROR(ctx, "Storage path is not set.", '\0');
136+
// ret_code = IPX_ERR_FORMAT;
137+
//}
138+
139+
//if (!cfg->files.suffix) {
140+
// IPX_CTX_ERROR(ctx, "File suffix is not set.", '\0');
141+
// ret_code = IPX_ERR_FORMAT;
142+
//}
143+
144+
//if (!cfg->file_lnf.prefix) {
145+
// IPX_CTX_ERROR(ctx, "LNF file prefix is not set.", '\0');
146+
// ret_code = IPX_ERR_FORMAT;
147+
//}
148+
149+
//if (cfg->file_index.en) {
150+
// if (!cfg->file_index.prefix) {
151+
// IPX_CTX_ERROR(ctx, "Index file prefix is not set.", '\0');
152+
// ret_code = IPX_ERR_FORMAT;
153+
// }
154+
155+
// if (cfg->file_index.est_cnt == 0) {
156+
// IPX_CTX_ERROR(ctx, "Estimated item count in Bloom Filter Index must be greater "
157+
// "than 0.", '\0');
158+
// ret_code = IPX_ERR_FORMAT;
159+
// }
160+
161+
// // Check output prefixes
162+
// if (strcmp(cfg->file_index.prefix, cfg->file_lnf.prefix) == 0) {
163+
// IPX_CTX_ERROR(ctx, "The same file prefix for LNF and Index file is not allowed");
164+
// ret_code = IPX_ERR_FORMAT;
165+
// }
166+
//}
167+
168+
//if (cfg->window.size == 0) {
169+
// IPX_CTX_ERROR(ctx, "Window size must be greater than 0.", '\0');
170+
// ret_code = IPX_ERR_FORMAT;
171+
//}
171172

172173
return ret_code;
173174
}
@@ -183,37 +184,37 @@ static int
183184
configuration_set_defaults(ipx_ctx_t *ctx, struct conf_params *cnf)
184185
{
185186
cnf->ctx = ctx;
186-
cnf->profiles.en = false; // Disabled by default
187+
//cnf->profiles.en = false; // Disabled by default
187188

188189
// Dump interval
189-
cnf->window.align = true;
190-
cnf->window.size = WINDOW_SIZE;
190+
//cnf->window.align = true;
191+
//cnf->window.size = WINDOW_SIZE;
191192

192193
// Files (common)
193-
cnf->files.suffix = strdup(SUFFIX_MASK);
194-
if (!cnf->files.suffix) {
195-
IPX_CTX_ERROR(ctx, "Unable to allocate memory (%s:%d)", __FILE__, __LINE__);
196-
return 1;
197-
}
194+
//cnf->files.suffix = strdup(SUFFIX_MASK);
195+
//if (!cnf->files.suffix) {
196+
// IPX_CTX_ERROR(ctx, "Unable to allocate memory (%s:%d)", __FILE__, __LINE__);
197+
// return 1;
198+
//}
198199

199200
// LNF file
200-
cnf->file_lnf.compress = false;
201-
cnf->file_lnf.prefix = strdup(LNF_FILE_PREFIX);
202-
if (!cnf->file_lnf.prefix) {
203-
IPX_CTX_ERROR(ctx, "Unable to allocate memory (%s:%d)", __FILE__, __LINE__);
204-
return 1;
205-
}
206-
207-
// Index file
208-
cnf->file_index.en = false;
209-
cnf->file_index.autosize = true;
210-
cnf->file_index.est_cnt = BF_DEFAULT_ITEM_CNT_EST;
211-
cnf->file_index.fp_prob = BF_DEFAULT_FP_PROB;
212-
cnf->file_index.prefix = strdup(BF_FILE_PREFIX);
213-
if (!cnf->file_index.prefix) {
214-
IPX_CTX_ERROR(ctx, "Unable to allocate memory (%s:%d)", __FILE__, __LINE__);
215-
return 1;
216-
}
201+
//cnf->file_lnf.compress = false;
202+
//cnf->file_lnf.prefix = strdup(LNF_FILE_PREFIX);
203+
//if (!cnf->file_lnf.prefix) {
204+
// IPX_CTX_ERROR(ctx, "Unable to allocate memory (%s:%d)", __FILE__, __LINE__);
205+
// return 1;
206+
//}
207+
208+
//// Index file
209+
//cnf->file_index.en = false;
210+
//cnf->file_index.autosize = true;
211+
//cnf->file_index.est_cnt = BF_DEFAULT_ITEM_CNT_EST;
212+
//cnf->file_index.fp_prob = BF_DEFAULT_FP_PROB;
213+
//cnf->file_index.prefix = strdup(BF_FILE_PREFIX);
214+
//if (!cnf->file_index.prefix) {
215+
// IPX_CTX_ERROR(ctx, "Unable to allocate memory (%s:%d)", __FILE__, __LINE__);
216+
// return 1;
217+
//}
217218

218219
return 0;
219220
}
@@ -238,11 +239,11 @@ configuration_parse_dump(ipx_ctx_t *ctx, fds_xml_ctx_t *dump, struct conf_params
238239
return IPX_ERR_DENIED;
239240
}
240241

241-
cnf->window.size = (uint32_t) content->val_uint;
242+
//cnf->window.size = (uint32_t) content->val_uint;
242243
break;
243244
case DUMP_ALIGN:
244245
assert(content->type == FDS_OPTS_T_BOOL);
245-
cnf->window.align = content->val_bool;
246+
//cnf->window.align = content->val_bool;
246247
break;
247248
default:
248249
assert(false);
@@ -269,19 +270,19 @@ configuration_parse_idx(ipx_ctx_t *ctx, fds_xml_ctx_t *idx, struct conf_params *
269270
switch (content->id) {
270271
case IDX_ENABLE:
271272
assert(content->type == FDS_OPTS_T_BOOL);
272-
cnf->file_index.en = content->val_bool;
273+
//cnf->file_index.en = content->val_bool;
273274
break;
274275
case IDX_AUTOSIZE:
275276
assert(content->type == FDS_OPTS_T_BOOL);
276-
cnf->file_index.autosize = content->val_bool;
277+
//cnf->file_index.autosize = content->val_bool;
277278
break;
278279
case IDX_COUNT:
279280
assert(content->type == FDS_OPTS_T_UINT);
280-
cnf->file_index.est_cnt = content->val_uint;
281+
//cnf->file_index.est_cnt = content->val_uint;
281282
break;
282283
case IDX_PROB:
283284
assert(content->type == FDS_OPTS_T_DOUBLE);
284-
cnf->file_index.fp_prob = content->val_double; // checked later in validator
285+
//cnf->file_index.fp_prob = content->val_double; // checked later in validator
285286
break;
286287
default:
287288
assert(false);
@@ -306,22 +307,22 @@ configuration_parse_root(ipx_ctx_t *ctx, fds_xml_ctx_t *root, struct conf_params
306307
switch (content->id) {
307308
case NODE_STORAGE:
308309
assert(content->type == FDS_OPTS_T_STRING);
309-
cnf->files.path = utils_path_preprocessor(content->ptr_string);
310-
if (!cnf->files.path) {
311-
const char *err_str;
312-
ipx_strerror(errno, err_str);
313-
IPX_CTX_ERROR(ctx, "Failed to process the <storagePath> expression: %s", err_str);
314-
return IPX_ERR_DENIED;
315-
}
310+
//cnf->files.path = content->ptr_string;
311+
//if (!cnf->files.path) {
312+
// const char *err_str;
313+
// ipx_strerror(errno, err_str);
314+
// IPX_CTX_ERROR(ctx, "Failed to process the <storagePath> expression: %s", err_str);
315+
// return IPX_ERR_DENIED;
316+
//}
316317
break;
317318
case NODE_ID_FIELD:
318319
assert(content->type == FDS_OPTS_T_STRING);
319-
free(cnf->file_lnf.ident);
320-
cnf->file_lnf.ident = strdup(content->ptr_string);
320+
//free(cnf->file_lnf.ident);
321+
//cnf->file_lnf.ident = strdup(content->ptr_string);
321322
break;
322323
case NODE_COMPRESS:
323324
assert(content->type == FDS_OPTS_T_BOOL);
324-
cnf->file_lnf.compress = content->val_bool;
325+
//cnf->file_lnf.compress = content->val_bool;
325326
break;
326327
case NODE_DUMP:
327328
assert(content->type == FDS_OPTS_T_CONTEXT);
@@ -405,29 +406,26 @@ configuration_parse(ipx_ctx_t *ctx, const char *params)
405406
}
406407

407408
void
408-
configuration_free(struct conf_params *config)
409+
configuration_free(struct conf_params *c)
409410
{
410-
if (!config) {
411+
if (!c) {
411412
return;
412413
}
413414

414-
free(config->files.path);
415+
free(c->trap_ifc_socket);
416+
c->trap_ifc_socket = NULL;
415417

416-
if (config->files.suffix) {
417-
free(config->files.suffix);
418-
}
418+
free(c->trap_ifc_timeout);
419+
c->trap_ifc_timeout = NULL;
419420

420-
if (config->file_lnf.prefix) {
421-
free(config->file_lnf.prefix);
422-
}
421+
free(c->trap_ifc_autoflush);
422+
c->trap_ifc_autoflush = NULL;
423423

424-
if (config->file_lnf.ident) {
425-
free(config->file_lnf.ident);
426-
}
424+
free(c->trap_ifc_bufferswitch);
425+
c->trap_ifc_bufferswitch = NULL;
427426

428-
if (config->file_index.prefix) {
429-
free(config->file_index.prefix);
430-
}
427+
free(c->unirec_format);
428+
c->unirec_format = NULL;
431429

432-
free(config);
430+
free(c);
433431
}

extra_plugins/output/unirec/configuration.h

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
2-
* \file configuration.c
2+
* \file configuration.h
33
* \author Tomas Cejka <[email protected]>
4+
* \author Jaroslav Hlavac <[email protected]>
45
* \brief Configuration parser (header file)
56
*/
67
/* Copyright (C) 2018 CESNET, z.s.p.o.
@@ -59,38 +60,49 @@
5960
struct conf_params {
6061
ipx_ctx_t *ctx; /**< Context of the instance (only for log!) */
6162

62-
struct {
63-
char *path; /**< Storage directory template.
64-
* This can be NULL only when profiles.en == true */
65-
char *suffix; /**< Common file suffix */
66-
} files; /**< Common storage templates */
63+
/**
64+
* TRAP interface type, e.g. t is for TCP, see https://nemea.liberouter.org/trap-ifcspec/
65+
*/
66+
char trap_ifc_type;
6767

68-
struct {
69-
char *prefix; /**< File prefix (can be NULL) */
70-
char *ident; /**< Internal file identification (can be NULL) */
71-
bool compress; /**< Enable/disable LZO compression */
72-
} file_lnf; /**< LNF configuration */
68+
/**
69+
* TRAP interface port / socket identifier. UniRec flows will be sent to this port
70+
*/
71+
char *trap_ifc_socket;
7372

74-
struct {
75-
bool en; /**< Enable/disable indexing. When disabled, other
76-
* parameters in this structure are undefined. */
77-
char *prefix; /**< File prefix */
78-
bool autosize; /**< Enable autosize */
73+
/**
74+
* TRAP interface timeout. it can be "NO_WAIT"/"HALF_WAIT"/"WAIT"/<number>
75+
*/
76+
char *trap_ifc_timeout;
7977

80-
uint64_t est_cnt; /**< Estimated item count in the filter */
81-
double fp_prob; /**< False positive probability of the filter */
82-
} file_index; /**< Bloom Filter Index configuration */
78+
/**
79+
* TRAP interface flush "off" or timeout in micro seconds
80+
*/
81+
char *trap_ifc_autoflush;
8382

84-
struct {
85-
bool align; /**< Enable/disable window alignment */
86-
uint32_t size; /**< Time window size */
87-
} window; /**< Window alignment */
83+
/**
84+
* TRAP interface buffer "on"/"off" or timeout in micro seconds
85+
*/
86+
char *trap_ifc_bufferswitch;
8887

89-
struct {
90-
bool en; /**< Enable/disable files generation based on
91-
* profiles. When it is enabled, files.path is
92-
* ignored */
93-
} profiles; /**< Profiles configuration */
88+
/**
89+
* TRAP interface UniRec template, elements marked with '?' are optional and might not be filled (e.g. TCP_FLAGS)
90+
* <UniRecFormat>DST_IP,SRC_IP,BYTES,DST_PORT,?TCP_FLAGS,SRC_PORT,PROTOCOL</UniRecFormat>
91+
* all fields must be contained in unirec-elements.txt
92+
*/
93+
char *unirec_format;
94+
95+
/**
96+
* A bit map representing the UR template that has all required fields set to 1.
97+
*/
98+
uint64_t bitmap_required;
99+
100+
/**
101+
* A bit map representing the UR template with all fields that were not filled set to 1.
102+
*
103+
* Index of a field in bitmap_required and bitmap_tofill can be the same as in ur_template_t.
104+
*/
105+
uint64_t bitmap_tofill;
94106
};
95107

96108
/**

extra_plugins/output/unirec/translator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
#include <string.h>
4343
#include <inttypes.h>
44-
#include "lnfstore.h"
44+
#include "unirecplugin.h"
4545
#include "translator.h"
4646
#include <unirec/unirec.h>
4747

0 commit comments

Comments
 (0)