Skip to content

Commit 7fd6a4b

Browse files
committed
Dummy output: fix invalid counting of bytes and packets of biflow records
1 parent 0744bcf commit 7fd6a4b

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/plugins/output/dummy/dummy.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646

4747
#include "config.h"
4848

49+
#define IANA_PEN 0
50+
#define IANA_PEN_REV 29305
51+
#define IE_ID_BYTES 1
52+
#define IE_ID_PKTS 2
53+
4954
/** Plugin description */
5055
IPX_API struct ipx_plugin_info ipx_plugin_info = {
5156
// Plugin type
@@ -57,7 +62,7 @@ IPX_API struct ipx_plugin_info ipx_plugin_info = {
5762
// Configuration flags (reserved for future use)
5863
.flags = 0,
5964
// Plugin version string (like "1.2.3")
60-
.version = "2.1.0",
65+
.version = "2.2.0",
6166
// Minimal IPFIXcol version string (like "1.2.3")
6267
.ipx_min = "2.0.0"
6368
};
@@ -91,7 +96,8 @@ stats_update(struct instance_data *inst, ipx_msg_ipfix_t *msg)
9196
// For each IPFIX Data Record
9297
for (uint32_t i = 0; i < rec_cnt; ++i) {
9398
struct ipx_ipfix_record *rec_ptr = ipx_msg_ipfix_get_drec(msg, i);
94-
enum fds_template_type ttype = rec_ptr->rec.tmplt->type;
99+
const struct fds_template *tmplt = rec_ptr->rec.tmplt;
100+
const enum fds_template_type ttype = tmplt->type;
95101

96102
struct fds_drec_field field;
97103
uint64_t value;
@@ -105,13 +111,30 @@ stats_update(struct instance_data *inst, ipx_msg_ipfix_t *msg)
105111
}
106112

107113
// Get octetDeltaCount
108-
if (fds_drec_find(&rec_ptr->rec, 0, 1, &field) != FDS_EOC
114+
if (fds_drec_find(&rec_ptr->rec, IANA_PEN, IE_ID_BYTES, &field) != FDS_EOC
109115
&& fds_get_uint_be(field.data, field.size, &value) == FDS_OK) {
110116
inst->cnt_bytes += value;
111117
}
112118

113119
// Get packetDeltaCount
114-
if (fds_drec_find(&rec_ptr->rec, 0, 2, &field) != FDS_EOC
120+
if (fds_drec_find(&rec_ptr->rec, IANA_PEN, IE_ID_PKTS, &field) != FDS_EOC
121+
&& fds_get_uint_be(field.data, field.size, &value) == FDS_OK) {
122+
inst->cnt_pkts += value;
123+
}
124+
125+
if ((tmplt->flags & FDS_TEMPLATE_BIFLOW) == 0) {
126+
// Not a biflow record
127+
continue;
128+
}
129+
130+
// Get octetDeltaCount (reverse)
131+
if (fds_drec_find(&rec_ptr->rec, IANA_PEN_REV, IE_ID_BYTES, &field) != FDS_EOC
132+
&& fds_get_uint_be(field.data, field.size, &value) == FDS_OK) {
133+
inst->cnt_bytes += value;
134+
}
135+
136+
// Get packetDeltaCount (reverse)
137+
if (fds_drec_find(&rec_ptr->rec, IANA_PEN_REV, IE_ID_PKTS, &field) != FDS_EOC
115138
&& fds_get_uint_be(field.data, field.size, &value) == FDS_OK) {
116139
inst->cnt_pkts += value;
117140
}

0 commit comments

Comments
 (0)