Skip to content

Commit 57a33fb

Browse files
committed
unirec: working prototype, must be tested
1 parent dc44cfa commit 57a33fb

File tree

11 files changed

+924
-668
lines changed

11 files changed

+924
-668
lines changed

extra_plugins/output/unirec/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ add_library(unirec-output MODULE
5252
unirecplugin.c
5353
translator.c
5454
translator.h
55+
fields.c
56+
fields.h
5557
)
5658

5759
target_link_libraries(unirec-output

extra_plugins/output/unirec/configuration.c

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* \brief Configuration parser (source file)
66
*/
77

8-
/* Copyright (C) 2016-2018 CESNET, z.s.p.o.
8+
/* Copyright (C) 2016-2018 CESNET, z.s.p.o.
99
*
1010
* Redistribution and use in source and binary forms, with or without
1111
* modification, are permitted provided that the following conditions
@@ -39,9 +39,12 @@
3939
*
4040
*/
4141

42+
#define _GNU_SOURCE
43+
#include <stdio.h>
4244
#include "configuration.h"
4345
#include "unirecplugin.h"
4446

47+
#include <ipfixcol2.h>
4548
#include <stdlib.h>
4649
#include <inttypes.h>
4750
#include <string.h>
@@ -281,3 +284,55 @@ configuration_free(struct conf_params *config)
281284

282285
free(config);
283286
}
287+
288+
char *
289+
configuration_create_ifcspec(ipx_ctx_t *ctx, const struct conf_params *parsed_params)
290+
{
291+
char *ifc_spec, *tmp_spec;
292+
int ret = asprintf(&ifc_spec, "%c:%s", parsed_params->trap_ifc_type, parsed_params->trap_ifc_socket);
293+
if (ret == -1) {
294+
IPX_CTX_ERROR(ctx, "Unable to create IFC spec (%s:%d)", __FILE__, __LINE__);
295+
return NULL;
296+
}
297+
298+
if (parsed_params->trap_ifc_bufferswitch) {
299+
int ret = asprintf(&tmp_spec, "%s:buffer=%s", ifc_spec, parsed_params->trap_ifc_bufferswitch);
300+
if (ret == -1) {
301+
IPX_CTX_ERROR(ctx, "Unable to create IFC spec (%s:%d)", __FILE__, __LINE__);
302+
free(ifc_spec);
303+
return NULL;
304+
} else {
305+
free(ifc_spec);
306+
ifc_spec = tmp_spec;
307+
tmp_spec = NULL;
308+
}
309+
}
310+
311+
if (parsed_params->trap_ifc_autoflush) {
312+
int ret = asprintf(&tmp_spec, "%s:autoflush=%s", ifc_spec, parsed_params->trap_ifc_autoflush);
313+
if (ret == -1) {
314+
IPX_CTX_ERROR(ctx, "Unable to create IFC spec (%s:%d)", __FILE__, __LINE__);
315+
free(ifc_spec);
316+
return NULL;
317+
} else {
318+
free(ifc_spec);
319+
ifc_spec = tmp_spec;
320+
tmp_spec = NULL;
321+
}
322+
}
323+
324+
if (parsed_params->trap_ifc_timeout) {
325+
int ret = asprintf(&tmp_spec, "%s:timeout=%s", ifc_spec, parsed_params->trap_ifc_timeout);
326+
if (ret == -1) {
327+
IPX_CTX_ERROR(ctx, "Unable to create IFC spec (%s:%d)", __FILE__, __LINE__);
328+
free(ifc_spec);
329+
return NULL;
330+
} else {
331+
free(ifc_spec);
332+
ifc_spec = tmp_spec;
333+
tmp_spec = NULL;
334+
}
335+
}
336+
return ifc_spec;
337+
}
338+

extra_plugins/output/unirec/configuration.h

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,37 @@
55
* \brief Configuration parser (header file)
66
*/
77
/* Copyright (C) 2018 CESNET, z.s.p.o.
8-
*
9-
* Redistribution and use in source and binary forms, with or without
10-
* modification, are permitted provided that the following conditions
11-
* are met:
12-
* 1. Redistributions of source code must retain the above copyright
13-
* notice, this list of conditions and the following disclaimer.
14-
* 2. Redistributions in binary form must reproduce the above copyright
15-
* notice, this list of conditions and the following disclaimer in
16-
* the documentation and/or other materials provided with the
17-
* distribution.
18-
* 3. Neither the name of the Company nor the names of its contributors
19-
* may be used to endorse or promote products derived from this
20-
* software without specific prior written permission.
21-
*
22-
* ALTERNATIVELY, provided that this notice is retained in full, this
23-
* product may be distributed under the terms of the GNU General Public
24-
* License (GPL) version 2 or later, in which case the provisions
25-
* of the GPL apply INSTEAD OF those given above.
26-
*
27-
* This software is provided ``as is, and any express or implied
28-
* warranties, including, but not limited to, the implied warranties of
29-
* merchantability and fitness for a particular purpose are disclaimed.
30-
* In no event shall the company or contributors be liable for any
31-
* direct, indirect, incidental, special, exemplary, or consequential
32-
* damages (including, but not limited to, procurement of substitute
33-
* goods or services; loss of use, data, or profits; or business
34-
* interruption) however caused and on any theory of liability, whether
35-
* in contract, strict liability, or tort (including negligence or
36-
* otherwise) arising in any way out of the use of this software, even
37-
* if advised of the possibility of such damage.
38-
*/
8+
*
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions
11+
* are met:
12+
* 1. Redistributions of source code must retain the above copyright
13+
* notice, this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright
15+
* notice, this list of conditions and the following disclaimer in
16+
* the documentation and/or other materials provided with the
17+
* distribution.
18+
* 3. Neither the name of the Company nor the names of its contributors
19+
* may be used to endorse or promote products derived from this
20+
* software without specific prior written permission.
21+
*
22+
* ALTERNATIVELY, provided that this notice is retained in full, this
23+
* product may be distributed under the terms of the GNU General Public
24+
* License (GPL) version 2 or later, in which case the provisions
25+
* of the GPL apply INSTEAD OF those given above.
26+
*
27+
* This software is provided ``as is, and any express or implied
28+
* warranties, including, but not limited to, the implied warranties of
29+
* merchantability and fitness for a particular purpose are disclaimed.
30+
* In no event shall the company or contributors be liable for any
31+
* direct, indirect, incidental, special, exemplary, or consequential
32+
* damages (including, but not limited to, procurement of substitute
33+
* goods or services; loss of use, data, or profits; or business
34+
* interruption) however caused and on any theory of liability, whether
35+
* in contract, strict liability, or tort (including negligence or
36+
* otherwise) arising in any way out of the use of this software, even
37+
* if advised of the possibility of such damage.
38+
*/
3939

4040
#ifndef CONFIGURATION_H
4141
#define CONFIGURATION_H
@@ -58,7 +58,10 @@
5858
* where the channel belongs.
5959
*/
6060
struct conf_params {
61-
ipx_ctx_t *ctx; /**< Context of the instance (only for log!) */
61+
/**
62+
* Context of the instance (only for log!)
63+
*/
64+
ipx_ctx_t *ctx;
6265

6366
/**
6467
* TRAP interface type, e.g. t is for TCP, see https://nemea.liberouter.org/trap-ifcspec/
@@ -91,36 +94,32 @@ struct conf_params {
9194
* all fields must be contained in unirec-elements.txt
9295
*/
9396
char *unirec_format;
94-
95-
/**
96-
* A bit map representing the UR template that has all required fields set to 1.
97-
*/
98-
uint64_t bitmap_required;
99-
100-
/**
101-
* A bit map representing the UR template with all fields that were not filled set to 1.
102-
*
103-
* Index of a field in bitmap_required and bitmap_tofill can be the same as in ur_template_t.
104-
*/
105-
uint64_t bitmap_tofill;
10697
};
10798

10899
/**
109100
* \brief Parse the plugin configuration
110101
*
111102
* \warning The configuration MUST be free by configuration_free() function.
103+
* \param[in,out] ctx IPFIXcol2 context for output messages
112104
* \param[in] params XML configuration
113105
* \return On success returns a pointer to the configuration. Otherwise returns
114106
* NULL.
115107
*/
116-
struct conf_params *
117-
configuration_parse(ipx_ctx_t *ctx, const char *params);
108+
struct conf_params *configuration_parse(ipx_ctx_t *ctx, const char *params);
118109

119110
/**
120111
* \brief Destroy the plugin configuration
121112
* \param[in,out] config Configuration
122113
*/
123-
void
124-
configuration_free(struct conf_params *config);
114+
void configuration_free(struct conf_params *config);
115+
116+
/**
117+
* Concatenate arguments from parsed configuration and create ifc_spec for trap_init()
118+
* \param[in,out] ctx IPFIXcol2 context for output messages
119+
* \param[in] parsed_params Information from configuration file
120+
* \return IFC specifier that can be passed to trap_*init()
121+
*/
122+
char *configuration_create_ifcspec(ipx_ctx_t *ctx, const struct conf_params *parsed_params);
125123

126124
#endif // CONFIGURATION_H
125+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/************* THIS IS AUTOMATICALLY GENERATED FILE, DO NOT EDIT *************/
2+
// Tables are indexed by field ID
3+
#include "fields.h"
4+
5+
char *ur_field_names_static[];
6+
short ur_field_sizes_static[];
7+
ur_field_type_t ur_field_types_static[];
8+
9+
ur_static_field_specs_t UR_FIELD_SPECS_STATIC = {ur_field_names_static, ur_field_sizes_static, ur_field_types_static, 0};
10+
ur_field_specs_t ur_field_specs = {ur_field_names_static, ur_field_sizes_static, ur_field_types_static, 0, 0, 0, NULL, UR_UNINITIALIZED};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef _UR_FIELDS_H_
2+
#define _UR_FIELDS_H_
3+
4+
/************* THIS IS AUTOMATICALLY GENERATED FILE, DO NOT EDIT *************/
5+
#include <unirec/unirec.h>
6+
7+
8+
extern uint16_t ur_last_id;
9+
extern ur_static_field_specs_t UR_FIELD_SPECS_STATIC;
10+
extern ur_field_specs_t ur_field_specs;
11+
12+
#endif
13+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<ipfixcol2>
2+
<inputPlugins>
3+
<input>
4+
<name>TCP collector</name>
5+
<plugin>tcp</plugin>
6+
<params>
7+
<localPort>4739</localPort>
8+
<localIPAddress></localIPAddress>
9+
</params>
10+
</input>
11+
</inputPlugins>
12+
13+
<outputPlugins>
14+
<output>
15+
<name>UniRec output</name>
16+
<plugin>unirec</plugin>
17+
<params>
18+
<trapIfcType>UNIXSOCKET</trapIfcType>
19+
<trapIfcSocket>ipfix-ur</trapIfcSocket>
20+
<UniRecFormat>TIME_FIRST,TIME_LAST,SRC_IP,DST_IP,PROTOCOL,?SRC_PORT,?DST_PORT,?TCP_FLAGS,PACKETS,BYTES</UniRecFormat>
21+
</params>
22+
</output>
23+
</outputPlugins>
24+
</ipfixcol2>

0 commit comments

Comments
 (0)