Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/plugins/intermediate/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# List of output plugin to build and install
add_subdirectory(anonymization)
add_subdirectory(filter)
add_subdirectory(filter)
add_subdirectory(extender)
28 changes: 28 additions & 0 deletions src/plugins/intermediate/extender/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
add_library(extender-intermediate MODULE
msg_builder.h
extender.c
config.c
config.h
)

install(
TARGETS extender-intermediate
LIBRARY DESTINATION "${INSTALL_DIR_LIB}/ipfixcol2/"
)

if (ENABLE_DOC_MANPAGE)
# Build a manual page
set(SRC_FILE "${CMAKE_CURRENT_SOURCE_DIR}/doc/ipfixcol2-extender-inter.7.rst")
set(DST_FILE "${CMAKE_CURRENT_BINARY_DIR}/ipfixcol2-extender-inter.7")

add_custom_command(TARGET extender-intermediate PRE_BUILD
COMMAND ${RST2MAN_EXECUTABLE} --syntax-highlight=none ${SRC_FILE} ${DST_FILE}
DEPENDS ${SRC_FILE}
VERBATIM
)

install(
FILES "${DST_FILE}"
DESTINATION "${INSTALL_DIR_MAN}/man7"
)
endif()
57 changes: 57 additions & 0 deletions src/plugins/intermediate/extender/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
============================
Extender (intermediate plugin)
============================

This intermediate plugin extends IPFIX records by adding new items to the existing record set using user-defined expressions.


Example configuration
---------------------

.. code-block:: xml

<intermediate>
<name>Extenders</name>
<plugin>extender</plugin>
<params>
<expr>dot1qCustomerVlanId == 0</expr>
<id>VRFname=default</id>
</params>
</intermediate>

The above sample adds a new string field ``VRFname=default`` to each IPFIX record if the existing field ``dot1qCustomerVlanId`` equals zero.


Parameters
----------

``expr``
The filter expression to evaluate.

``id``
The identifier string to be added to the record when the expression evaluates to true.


Supported operations
--------------------

Comparisons
- Operators: ``==``, ``<``, ``>``, ``<=``, ``>=``, ``!=``
- Default: ``==`` (if the operator is omitted)

Substring Matching
- Operator: ``contains``
- Example: ``DNSName contains "example"``

Arithmetic
- Operators: ``+``, ``-``, ``*``, ``/``, ``%``

Bitwise Logic
- Operators: ``~`` (not), ``|`` (or), ``&`` (and), ``^`` (xor)

List Membership
- Operator: ``in``
- Example: ``port in [80, 443]``

Logical Operators
- Operators: ``and``, ``or``, ``not``
198 changes: 198 additions & 0 deletions src/plugins/intermediate/extender/config.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
/**
* \file src/plugins/intermediate/filter/config.c
* \author Michal Sedlak <xsedla0v@stud.fit.vutbr.cz>
* \brief The filter plugin config
* \date 2020
*/

/* Copyright (C) 2020 CESNET, z.s.p.o.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of the Company nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* ALTERNATIVELY, provided that this notice is retained in full, this
* product may be distributed under the terms of the GNU General Public
* License (GPL) version 2 or later, in which case the provisions
* of the GPL apply INSTEAD OF those given above.
*
* This software is provided ``as is'', and any express or implied
* warranties, including, but not limited to, the implied warranties of
* merchantability and fitness for a particular purpose are disclaimed.
* In no event shall the company or contributors be liable for any
* direct, indirect, incidental, special, exemplary, or consequential
* damages (including, but not limited to, procurement of substitute
* goods or services; loss of use, data, or profits; or business
* interruption) however caused and on any theory of liability, whether
* in contract, strict liability, or tort (including negligence or
* otherwise) arising in any way out of the use of this software, even
* if advised of the possibility of such damage.
*
*/

#include "config.h"

#include <string.h>
#include <stdlib.h>

/*
* <params>
* <expr>...</expr>
* </params>
*/

enum params_xml_nodes {
FILTER_EXPR = 1,
EXTENSION_ID = 2,
EXTENSION_VALUE = 3,
IDS = 4
};

static const struct fds_xml_args ids_params[] = {
FDS_OPTS_ELEM(FILTER_EXPR, "expr", FDS_OPTS_T_STRING, 0),
FDS_OPTS_ELEM(EXTENSION_ID, "id", FDS_OPTS_T_STRING, 0),
FDS_OPTS_ELEM(EXTENSION_VALUE, "value", FDS_OPTS_T_STRING, 0),
FDS_OPTS_END
};

static const struct fds_xml_args args_params[] = {
FDS_OPTS_ROOT("params"),
FDS_OPTS_NESTED(IDS, "ids", ids_params, FDS_OPTS_P_OPT | FDS_OPTS_P_MULTI),
FDS_OPTS_END
};


struct config *
config_parse(ipx_ctx_t *ctx, const char *params)
{
struct config *cfg = NULL;
fds_xml_t *parser = NULL;

cfg = calloc(1, sizeof(struct config));
if (!cfg) {
IPX_CTX_ERROR(ctx, "Memory allocation error (%s:%d)", __FILE__, __LINE__);
goto error;
}

parser = fds_xml_create();
if (!parser) {
IPX_CTX_ERROR(ctx, "Memory allocation error (%s:%d)", __FILE__, __LINE__);
goto error;
}

if (fds_xml_set_args(parser, args_params) != FDS_OK) {
IPX_CTX_ERROR(ctx, "Failed to parse the description of an XML document!");
goto error;
}

fds_xml_ctx_t *params_ctx = fds_xml_parse_mem(parser, params, true);
if (params_ctx == NULL) {
IPX_CTX_ERROR(ctx, "Failed to parse the configuration: %s", fds_xml_last_err(parser));
goto error;
}

const struct fds_xml_cont *content;
while (fds_xml_next(params_ctx, &content) == FDS_OK) {
switch (content->id) {
case IDS:
{
if( cfg->ids_count >= CONFIG_IDS_MAX ) {
IPX_CTX_ERROR(ctx, "Maximum number of extension IDs exceeded (%d)!", CONFIG_IDS_MAX);
goto error;
}
config_ids_t* id = &cfg->ids[cfg->ids_count];
id->expr = NULL;
id->name = NULL;
cfg->ids_count++;
const struct fds_xml_cont *id_content;
while (fds_xml_next(content->ptr_ctx, &id_content) == FDS_OK) {
switch (id_content->id) {
case FILTER_EXPR:
assert(id_content->type == FDS_OPTS_T_STRING);
if (strlen(id_content->ptr_string) == 0) {
IPX_CTX_ERROR(ctx, "Filter expression is empty!");
goto error;
}
id->expr = strdup(id_content->ptr_string);
if (!id->expr) {
IPX_CTX_ERROR(ctx, "Memory allocation error (%s:%d)", __FILE__, __LINE__);
goto error;
}
break;
case EXTENSION_ID:
// Ignored in this plugin
assert(id_content->type == FDS_OPTS_T_STRING);
if (strlen(id_content->ptr_string) == 0) {
IPX_CTX_ERROR(ctx, "Extension ID is empty!");
goto error;
}
id->name = strdup(id_content->ptr_string);
if (!id->name) {
IPX_CTX_ERROR(ctx, "Memory allocation error (%s:%d)", __FILE__, __LINE__);
goto error;
}
break;
case EXTENSION_VALUE:
assert(id_content->type == FDS_OPTS_T_STRING);
if (strlen(id_content->ptr_string) == 0) {
IPX_CTX_ERROR(ctx, "Extension value is empty!");
goto error;
}
id->value = strdup(id_content->ptr_string);
if (!id->value) {
IPX_CTX_ERROR(ctx, "Memory allocation error (%s:%d)", __FILE__, __LINE__);
goto error;
}
break;
}
}
break;
}
}
}

fds_xml_destroy(parser);
return cfg;

error:
fds_xml_destroy(parser);
config_destroy(cfg);
return NULL;
}

void
config_destroy(struct config *cfg)
{
if (cfg == NULL) {
return;
}
for( int i = 0; i < cfg->ids_count; i++) {
printf("Free filter %s\n", cfg->ids[i].name);
if( cfg->ids[i].expr ) {
free(cfg->ids[i].expr);
cfg->ids[i].expr = NULL;
}
if( cfg->ids[i].filter ) {
fds_ipfix_filter_destroy(cfg->ids[i].filter);
cfg->ids[i].filter = NULL;
}
if( cfg->ids[i].value ) {
free(cfg->ids[i].value);
cfg->ids[i].value = NULL;
}
if( cfg->ids[i].name ) {
free(cfg->ids[i].name);
cfg->ids[i].name = NULL;
}
}
free(cfg);
}
69 changes: 69 additions & 0 deletions src/plugins/intermediate/extender/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* \file src/plugins/intermediate/filter/config.h
* \author Michal Sedlak <xsedla0v@stud.fit.vutbr.cz>
* \brief The filter plugin config header
* \date 2020
*/

/* Copyright (C) 2020 CESNET, z.s.p.o.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of the Company nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* ALTERNATIVELY, provided that this notice is retained in full, this
* product may be distributed under the terms of the GNU General Public
* License (GPL) version 2 or later, in which case the provisions
* of the GPL apply INSTEAD OF those given above.
*
* This software is provided ``as is'', and any express or implied
* warranties, including, but not limited to, the implied warranties of
* merchantability and fitness for a particular purpose are disclaimed.
* In no event shall the company or contributors be liable for any
* direct, indirect, incidental, special, exemplary, or consequential
* damages (including, but not limited to, procurement of substitute
* goods or services; loss of use, data, or profits; or business
* interruption) however caused and on any theory of liability, whether
* in contract, strict liability, or tort (including negligence or
* otherwise) arising in any way out of the use of this software, even
* if advised of the possibility of such damage.
*
*/

#ifndef CONFIG_H
#define CONFIG_H

#define CONFIG_IDS_MAX 12

#include <ipfixcol2.h>

typedef struct config_ids {
char *expr;
char* name;
char* value;
uint16_t id;
enum fds_iemgr_element_type data_type;
fds_ipfix_filter_t *filter;
} config_ids_t;

struct config {
int ids_count;
config_ids_t ids[CONFIG_IDS_MAX];
};

struct config *
config_parse(ipx_ctx_t *ctx, const char *params);

void
config_destroy(struct config *cfg);

#endif // CONFIG_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
========================
ipfixcol2-extender
========================

-----------------------------------
Extender (intermediate plugin)
-----------------------------------

:Author: Jimmy Björklund (jimmy@lolo.company)
:Date: 2026-01-14
:Copyright: Copyright © 2026 CESNET, z.s.p.o.
:Version: 1.0
:Manual section: 7
:Manual group: IPFIXcol collector

Description
-----------

.. include:: ../README.rst
:start-line: 3
Loading