Skip to content

Commit 1c74c42

Browse files
committed
unirec: install unirec-elements.txt, load it from IPFIXcol2 sysconfdir
1 parent 19c7d44 commit 1c74c42

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

extra_plugins/output/unirec/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,8 @@ install(
6565
TARGETS unirec-output
6666
LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/ipfixcol2/"
6767
)
68+
install(
69+
FILES unirec-elements.txt
70+
DESTINATION "${CMAKE_INSTALL_FULL_SYSCONFDIR}/ipfixcol2/"
71+
)
72+

extra_plugins/output/unirec/translator.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
*
4040
*/
4141

42+
#define _GNU_SOURCE /* See feature_test_macros(7) */
43+
#include <stdio.h>
4244
#include <string.h>
4345
#include <inttypes.h>
4446
#include "unirecplugin.h"
@@ -77,7 +79,7 @@ translate_bool(const struct fds_drec_field *field, struct conf_unirec *conf,
7779

7880

7981
// Path to unirec elements config file
80-
const char *UNIREC_ELEMENTS_FILE = "./unirec-elements.txt"; //TODO is this where it should be located
82+
const char *UNIREC_ELEMENTS_FILE = "unirec-elements.txt";
8183

8284
/**
8385
* \brief Creates IPFIX id from string
@@ -113,12 +115,26 @@ unirecField_t *load_IPFIX2UR_mapping(ipx_ctx_t *ctx, uint32_t *urcount, uint32_t
113115
uint32_t numurfields = 0;
114116
uint32_t numipfixfields = 0;
115117

118+
const char *sysconfdir = ipx_api_cfg_dir();
119+
if (sysconfdir == NULL) {
120+
/* if the IPFIXcol2's path to config dir is not known, use current dir */
121+
IPX_CTX_WARNING(ctx, "IPFIXcol2 did not supply path to config files, using \"./\" instead.");
122+
sysconfdir = ".";
123+
}
124+
char *path_conf = NULL;
125+
if (asprintf(&path_conf, "%s/%s", sysconfdir, UNIREC_ELEMENTS_FILE) == -1) {
126+
IPX_CTX_ERROR(ctx, "Could not allocate memory (%s:%d).", __FILE__, __LINE__);
127+
return NULL;
128+
}
129+
116130
/* Open the file */
117-
uef = fopen(UNIREC_ELEMENTS_FILE, "r");
131+
uef = fopen(path_conf, "r");
118132
if (uef == NULL) {
119-
IPX_CTX_ERROR(ctx, "Could not open file \"%s\" (%s:%d)", UNIREC_ELEMENTS_FILE, __FILE__, __LINE__);
133+
IPX_CTX_ERROR(ctx, "Could not open file \"%s\" (%s:%d)", path_conf, __FILE__, __LINE__);
120134
return NULL;
121135
}
136+
free(path_conf);
137+
path_conf = NULL;
122138

123139
/* Init buffer */
124140
line = malloc(lineSize);

0 commit comments

Comments
 (0)