Skip to content

Commit 61838a1

Browse files
committed
JSON output: add option to prevent field conversion of octetArray as unsigned integer
The added option preseves the previous behaviour by default.
1 parent a113629 commit 61838a1

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

src/plugins/output/json/README.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Don't forget to remove (or comment) outputs that you don't want to use!
8989
<ignoreUnknown>true</ignoreUnknown>
9090
<ignoreOptions>true</ignoreOptions>
9191
<nonPrintableChar>true</nonPrintableChar>
92+
<octetArrayAsUint>true</octetArrayAsUint>
9293
<numericNames>false</numericNames>
9394
<splitBiflow>false</splitBiflow>
9495
<detailedInfo>false</detailedInfo>
@@ -145,8 +146,8 @@ Formatting parameters:
145146

146147
:``ignoreUnknown``:
147148
Skip unknown Information Elements (i.e. record fields with unknown name and data type).
148-
If disabled, data of unknown elements are formatted as unsigned integer (the size of the
149-
field ≤ 8 bytes) or binary values. [values: true/false, default: true]
149+
If disabled, data of unknown elements are formatted as unsigned integer or hexadecimal values.
150+
For more information, see ``octetArrayAsUint`` option. [values: true/false, default: true]
150151

151152
:``ignoreOptions``:
152153
Skip non-flow records used for reporting metadata about IPFIX Exporting and Metering Processes
@@ -156,6 +157,15 @@ Formatting parameters:
156157
Ignore non-printable characters (newline, tab, control characters, etc.) in IPFIX strings.
157158
If disabled, these characters are escaped on output. [values: true/false, default: true]
158159

160+
:``octetArrayAsUint``:
161+
Converter each IPFIX field with octetArray type (including IPFIX fields with unknown
162+
definitions) as unsigned integer if the size of the field is less or equal to 8 bytes.
163+
Fields with the size above the limit are always converted as string representing hexadecimal
164+
value, which is typically in network byte order (e.g. "0x71E1"). Keep on mind, that there might
165+
be octetArray fields with variable length that might be interpreted differently based on their
166+
size. If disabled, octetArray fields are never interpreted as unsigned integers.
167+
[values: true/false, default: true]
168+
159169
:``numericNames``:
160170
Use only short identification of Information Elements (i.e. "enXX:idYY"). If enabled, the
161171
short version is used even if the definition of the field is known. This option can help to

src/plugins/output/json/src/Config.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ enum params_xml_nodes {
5757
FMT_UNKNOWN, /**< Unknown definitions */
5858
FMT_OPTIONS, /**< Ignore Options Template Records */
5959
FMT_NONPRINT, /**< Non-printable chars */
60+
FMT_OCTETASUINT, /**< OctetArray as unsigned integer */
6061
FMT_NUMERIC, /**< Use numeric names */
6162
FMT_BFSPLIT, /**< Split biflow */
6263
FMT_DETAILEDINFO, /**< Detailed information */
63-
FMT_TMPLTINFO, /**< Template records */
64+
FMT_TMPLTINFO, /**< Template records */
6465
// Common output
6566
OUTPUT_LIST, /**< List of output types */
6667
OUTPUT_PRINT, /**< Print to standard output */
@@ -142,6 +143,7 @@ static const struct fds_xml_args args_params[] = {
142143
FDS_OPTS_ELEM(FMT_OPTIONS, "ignoreOptions", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
143144
FDS_OPTS_ELEM(FMT_NONPRINT, "nonPrintableChar", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
144145
FDS_OPTS_ELEM(FMT_NUMERIC, "numericNames", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
146+
FDS_OPTS_ELEM(FMT_OCTETASUINT, "octetArrayAsUint", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
145147
FDS_OPTS_ELEM(FMT_BFSPLIT, "splitBiflow", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
146148
FDS_OPTS_ELEM(FMT_DETAILEDINFO, "detailedInfo", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
147149
FDS_OPTS_ELEM(FMT_TMPLTINFO, "templateInfo", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
@@ -472,6 +474,10 @@ Config::parse_params(fds_xml_ctx_t *params)
472474
assert(content->type == FDS_OPTS_T_BOOL);
473475
format.numeric_names = content->val_bool;
474476
break;
477+
case FMT_OCTETASUINT:
478+
assert(content->type == FDS_OPTS_T_BOOL);
479+
format.octets_as_uint = content->val_bool;
480+
break;
475481
case FMT_BFSPLIT: // Split biflow records
476482
assert(content->type == FDS_OPTS_T_BOOL);
477483
format.split_biflow = content->val_bool;
@@ -506,6 +512,7 @@ Config::default_set()
506512
format.white_spaces = true;
507513
format.ignore_unknown = true;
508514
format.ignore_options = true;
515+
format.octets_as_uint = true;
509516
format.numeric_names = false;
510517
format.split_biflow = false;
511518
format.detailed_info = false;

src/plugins/output/json/src/Config.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ struct cfg_format {
5656
bool proto;
5757
/** Skip unknown elements */
5858
bool ignore_unknown;
59+
/** Converter octetArray type as unsigned integer (only if field size <= 8) */
60+
bool octets_as_uint;
5961
/** Convert white spaces in string (do not skip) */
6062
bool white_spaces;
61-
/** Add detailed information about each record */
63+
/** Add detailed information about each record */
6264
bool detailed_info;
6365
/** Ignore Options Template records */
6466
bool ignore_options;

src/plugins/output/json/src/Storage.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ Storage::Storage(const ipx_ctx_t *ctx, const struct cfg_format &fmt)
8383
if (m_format.split_biflow) {
8484
m_flags |= FDS_CD2J_REVERSE_SKIP;
8585
}
86-
86+
if (!m_format.octets_as_uint) {
87+
m_flags |= FDS_CD2J_OCTETS_NOINT;
88+
}
8789
}
8890

8991
Storage::~Storage()

0 commit comments

Comments
 (0)