From 300940a1b0b0f73e43862cae49e1c4c63558a559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Bj=C3=B6rklund?= Date: Mon, 22 Dec 2025 07:59:02 +0000 Subject: [PATCH] Added the abulity to exclude items from the json conversion --- include/libfds/iemgr.h | 2 ++ src/converters/json.c | 13 ++++++++++++- src/iemgr/iemgr.cpp | 3 ++- src/iemgr/iemgr_common.h | 1 + src/iemgr/iemgr_element.cpp | 10 +++++++--- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/libfds/iemgr.h b/include/libfds/iemgr.h index 7cedc63..d386f21 100644 --- a/include/libfds/iemgr.h +++ b/include/libfds/iemgr.h @@ -303,6 +303,8 @@ struct fds_iemgr_elem { struct fds_iemgr_mapping ** mappings; size_t mappings_cnt; + /** Exclusion flag, tells weather a fields should be excluded from export */ + bool excluded; }; /** diff --git a/src/converters/json.c b/src/converters/json.c index a72ea6e..10d0c6b 100644 --- a/src/converters/json.c +++ b/src/converters/json.c @@ -976,6 +976,14 @@ get_converter(const struct fds_drec_field *field) } } +static bool match_exclude(const struct fds_drec_iter* iter) +{ + if( iter->field.info->def == NULL || iter->field.info->def->excluded) { + return true; + } + return false; +} + /** * \breaf Function for iterating through Information Elements * \param[in] rec IPFIX Data Record to convert @@ -1001,13 +1009,16 @@ iter_loop(const struct fds_drec *rec, struct context *buffer) fds_drec_iter_init(&iter, (struct fds_drec *) rec, iter_flag); while (fds_drec_iter_next(&iter) != FDS_EOC) { + // If flag of multi fields is set, // then this field will be skiped and processed when the last occurrence is found const fds_template_flag_t field_flags = iter.field.info->flags; if ((field_flags & FDS_TFIELD_MULTI_IE) != 0 && (field_flags & FDS_TFIELD_LAST_IE) == 0){ continue; } - + if ( match_exclude( &iter ) ) { + continue; + } // Separate fields if (added != 0) { // Add comma diff --git a/src/iemgr/iemgr.cpp b/src/iemgr/iemgr.cpp index ceb8fbc..54d2731 100644 --- a/src/iemgr/iemgr.cpp +++ b/src/iemgr/iemgr.cpp @@ -319,7 +319,8 @@ parser_create(fds_iemgr_t* mgr) FDS_OPTS_ELEM(ELEM_DATA_SEMAN, "dataSemantics", FDS_OPTS_T_STRING, FDS_OPTS_P_OPT), FDS_OPTS_ELEM(ELEM_DATA_UNIT, "units", FDS_OPTS_T_STRING, FDS_OPTS_P_OPT), FDS_OPTS_ELEM(ELEM_STATUS, "status", FDS_OPTS_T_STRING, FDS_OPTS_P_OPT), - FDS_OPTS_ELEM(ELEM_BIFLOW, "biflowId", FDS_OPTS_T_INT, FDS_OPTS_P_OPT), + FDS_OPTS_ELEM(ELEM_BIFLOW, "biflowId", FDS_OPTS_T_INT, FDS_OPTS_P_OPT), + FDS_OPTS_ELEM(ELEM_EXCLUDED, "excluded", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT), FDS_OPTS_END }; static const struct fds_xml_args args_biflow[] = { diff --git a/src/iemgr/iemgr_common.h b/src/iemgr/iemgr_common.h index 3dbd22e..1f8cf39 100644 --- a/src/iemgr/iemgr_common.h +++ b/src/iemgr/iemgr_common.h @@ -167,6 +167,7 @@ enum FDS_XML_ID { ITEM_LIST_ITEM, ITEM_KEY, ITEM_VALUE, + ELEM_EXCLUDED }; /** \cond DOXYGEN_SKIP_THIS */ diff --git a/src/iemgr/iemgr_element.cpp b/src/iemgr/iemgr_element.cpp index 9e55364..1ae5931 100644 --- a/src/iemgr/iemgr_element.cpp +++ b/src/iemgr/iemgr_element.cpp @@ -60,6 +60,7 @@ element_create() elem->aliases_cnt = 0; elem->mappings = nullptr; elem->mappings_cnt = 0; + elem->excluded = false; return elem; } @@ -81,7 +82,7 @@ element_copy(fds_iemgr_scope_inter* scope, const fds_iemgr_elem* elem) res->aliases = copy_flat_array(elem->aliases, elem->aliases_cnt); res->mappings_cnt = elem->mappings_cnt; res->mappings = copy_flat_array(elem->mappings, elem->mappings_cnt); - + res->excluded = elem->excluded; return res; } @@ -102,8 +103,8 @@ element_create_reverse(fds_iemgr_elem* src, uint16_t new_id) res->aliases = nullptr; res->mappings_cnt = 0; res->mappings = nullptr; - - src->reverse_elem = res.get(); + res->excluded = src->excluded; + src->reverse_elem = res.get(); return res.release(); } @@ -376,6 +377,9 @@ element_read(fds_iemgr_t* mgr, fds_xml_ctx_t* ctx, fds_iemgr_scope_inter* scope) return false; } break; + case ELEM_EXCLUDED: + elem->excluded = cont->val_bool; + break; default: break; }