Skip to content

Commit 14945b4

Browse files
committed
UniRec output: add splitBiflow option
Note: To preserve current behaviour the option is enabled by default.
1 parent 5474f78 commit 14945b4

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

doc/data/configs/tcp2unirec.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
Receive flow data over TCP, convert them into UniRec format and send via
2+
Receive flow data over TCP, convert them into UniRec format and send via
33
TCP TRAP communication interface (port 8000).
44
-->
55
<ipfixcol2>
@@ -23,6 +23,7 @@
2323
<params>
2424
<!-- UniRec template -->
2525
<uniRecFormat>TIME_FIRST,TIME_LAST,SRC_IP,DST_IP,PROTOCOL,?SRC_PORT,?DST_PORT,?TCP_FLAGS,PACKETS,BYTES</uniRecFormat>
26+
<splitBiflow>true</splitBiflow>
2627
<!-- TRAP interface configuration -->
2728
<trapIfcCommon>
2829
<timeout>HALF_WAIT</timeout>

extra_plugins/output/unirec/README.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ except the one you would like to use.
5050
<plugin>unirec</plugin>
5151
<params>
5252
<uniRecFormat>TIME_FIRST,TIME_LAST,SRC_IP,DST_IP,PROTOCOL,?SRC_PORT,?DST_PORT,?TCP_FLAGS,PACKETS,BYTES</uniRecFormat>
53+
<splitBiflow>false</splitBiflow>
54+
5355
<trapIfcCommon>
5456
<timeout>NO_WAIT</timeout>
5557
<buffer>true</buffer>
@@ -92,6 +94,10 @@ Parameters
9294
fields is defined in `unirec-element.txt <config/unirec-elements.txt>`_ file.
9395
Example value: "DST_IP,SRC_IP,BYTES,DST_PORT,?TCP_FLAGS,SRC_PORT,PROTOCOL".
9496

97+
:``splitBiflow``:
98+
In case of Biflow records, split the record to two unidirectional flow records. Non-biflow
99+
records are unaffected. [values: true/false, default: true]
100+
95101
:``trapIfcCommon``:
96102
The following parameters can be used with any type of a TRAP interface. There are parameters
97103
of the interface that are normally let default. However, it is possible to override them
@@ -247,9 +253,6 @@ with increased verbosity level i.e. ``ipfixcol2 -v``.
247253
Notes
248254
-----
249255

250-
Bidirectional flows are not currently supported by UniRec, therefore, biflow records are
251-
automatically split into two unidirectional flow records during conversion.
252-
253256
When multiple IPFIX Information Elements are mapped to the same UniRec field and those IPFIX fields
254257
are present in an IPFIX record, the last field occurrence (in the appropriate IPFIX Template)
255258
is converted to the UniRec field.

extra_plugins/output/unirec/src/configuration.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct ifc_common {
8585
/*
8686
* <params>
8787
* <uniRecFormat>DST_IP,SRC_IP,BYTES,DST_PORT,?TCP_FLAGS,SRC_PORT,PROTOCOL</uniRecFormat>
88+
* <splitBiflow>true</splitBiflow>
8889
* <trapIfcCommon> <!-- optional -->
8990
* <timeout>NO_WAIT</timeout> <!-- optional -->
9091
* <buffer>true</buffer> <!-- optional -->
@@ -121,6 +122,7 @@ struct ifc_common {
121122
enum params_xml_nodes {
122123
// Main parameters
123124
NODE_UNIREC_FMT = 1,
125+
NODE_BIFLOW_SPLIT,
124126
NODE_TRAP_COMMON,
125127
NODE_TRAP_SPEC,
126128
// TRAP common parameters
@@ -205,6 +207,7 @@ static const struct fds_xml_args args_trap_common[] = {
205207
static const struct fds_xml_args args_params[] = {
206208
FDS_OPTS_ROOT("params"),
207209
FDS_OPTS_ELEM(NODE_UNIREC_FMT, "uniRecFormat", FDS_OPTS_T_STRING, 0),
210+
FDS_OPTS_ELEM(NODE_BIFLOW_SPLIT, "splitBiflow", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
208211
FDS_OPTS_NESTED(NODE_TRAP_COMMON, "trapIfcCommon", args_trap_common, FDS_OPTS_P_OPT),
209212
FDS_OPTS_NESTED(NODE_TRAP_SPEC, "trapIfcSpec", args_trap_spec, 0),
210213
FDS_OPTS_END
@@ -775,7 +778,10 @@ cfg_parse_params(ipx_ctx_t *ctx, fds_xml_ctx_t *root, struct conf_params *cfg)
775778
{
776779
int rc;
777780

778-
// Prepare default TRAP common parameters
781+
// Set default values
782+
cfg->biflow_split = true;
783+
784+
// Set default TRAP common parameters
779785
struct ifc_common common;
780786
common.autoflush = DEF_IFC_AUTOFLUSH;
781787
common.buffer = DEF_IFC_BUFFER;
@@ -795,6 +801,11 @@ cfg_parse_params(ipx_ctx_t *ctx, fds_xml_ctx_t *root, struct conf_params *cfg)
795801
return IPX_ERR_NOMEM;
796802
}
797803
break;
804+
case NODE_BIFLOW_SPLIT:
805+
// Split biflow
806+
assert(content->type == FDS_OPTS_T_BOOL);
807+
cfg->biflow_split = content->val_bool;
808+
break;
798809
case NODE_TRAP_SPEC:
799810
// TRAP output interface specifier
800811
assert(content->type == FDS_OPTS_T_CONTEXT);

extra_plugins/output/unirec/src/configuration.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ struct conf_params {
5959
char *unirec_spec;
6060
/** The same as \ref conf_params.unirec_spec, however, question marks have been removed */
6161
char *unirec_fmt;
62+
/** Split biflow record to 2 unidirectional flows */
63+
bool biflow_split;
6264
};
6365

6466
/**

extra_plugins/output/unirec/src/unirecplugin.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ IPX_API struct ipx_plugin_info ipx_plugin_info = {
7878
// Configuration flags (reserved for future use)
7979
.flags = 0,
8080
// Plugin version string (like "1.2.3")
81-
.version = "2.1.0",
81+
.version = "2.2.0",
8282
// Minimal IPFIXcol version string (like "1.2.3")
8383
.ipx_min = "2.0.0"
8484
};
@@ -354,6 +354,7 @@ ipx_plugin_process(ipx_ctx_t *ctx, void *cfg, ipx_msg_t *msg)
354354
{
355355
(void) ctx;
356356
struct conf_unirec *conf = (struct conf_unirec *) cfg;
357+
const bool split_enabled = conf->params->biflow_split;
357358
IPX_CTX_DEBUG(ctx, "Received a new message to process.");
358359

359360
uint16_t msg_size = 0;
@@ -367,10 +368,11 @@ ipx_plugin_process(ipx_ctx_t *ctx, void *cfg, ipx_msg_t *msg)
367368
for (uint32_t i = 0; i < rec_cnt; i++) {
368369
// Get a pointer to the next record
369370
struct ipx_ipfix_record *ipfix_rec = ipx_msg_ipfix_get_drec(ipfix, i);
370-
bool biflow = (ipfix_rec->rec.tmplt->flags & FDS_TEMPLATE_BIFLOW) != 0;
371+
bool rec_is_biflow = (ipfix_rec->rec.tmplt->flags & FDS_TEMPLATE_BIFLOW) != 0;
372+
bool biflow_split = split_enabled && rec_is_biflow;
371373

372-
// Fill record
373-
uint16_t flags = biflow ? FDS_DREC_BIFLOW_FWD : 0; // In case of biflow, forward fields only
374+
// Fill record (Note: in case of biflow split, forward fields only)
375+
uint16_t flags = biflow_split ? (FDS_DREC_BIFLOW_FWD | FDS_DREC_REVERSE_SKIP) : 0;
374376
msg_data = translator_translate(conf->trans, &ipfix_rec->rec, flags, &msg_size);
375377
if (!msg_data) {
376378
// Nothing to send
@@ -380,12 +382,12 @@ ipx_plugin_process(ipx_ctx_t *ctx, void *cfg, ipx_msg_t *msg)
380382
IPX_CTX_DEBUG(ctx, "Send via TRAP IFC.");
381383
trap_ctx_send(conf->trap_ctx, 0, msg_data, msg_size);
382384

383-
// Is it biflow? Send the reverse direction
384-
if (!biflow) {
385+
// Is it biflow and split is enabled? Send the reverse direction
386+
if (!biflow_split) {
385387
continue;
386388
}
387389

388-
flags = FDS_DREC_BIFLOW_REV;
390+
flags = FDS_DREC_BIFLOW_REV | FDS_DREC_REVERSE_SKIP;
389391
msg_data = translator_translate(conf->trans, &ipfix_rec->rec, flags, &msg_size);
390392
if (!msg_data) {
391393
// Nothing to send

0 commit comments

Comments
 (0)