Skip to content

Commit 82898e5

Browse files
BonnyAD9sedmicha
authored andcommitted
TCP - implement the collector input plugin functions
1 parent dde3b11 commit 82898e5

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

src/plugins/input/tcp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ add_library(tcp-input MODULE
1212
src/DecoderFactory.cpp
1313
src/Acceptor.cpp
1414
src/Plugin.cpp
15+
src/IpxPlugin.cpp
1516
)
1617

1718
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_HOST_SYSTEM_NAME STREQUAL "OpenBSD")
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* \file
3+
* \author Jakub Antonín Štigler <[email protected]>
4+
* \brief ipfixcol2 API for tcp input plugin
5+
* \date 2024
6+
*
7+
* Copyright: (C) 2023 CESNET, z.s.p.o.
8+
* SPDX-License-Identifier: BSD-3-Clause
9+
*/
10+
11+
#include <stdexcept> // exception
12+
13+
#include <ipfixcol2.h> // IPX_*, ipx_*
14+
15+
#include "Config.hpp" // Config
16+
#include "Plugin.hpp" // Plugin
17+
18+
IPX_API struct ipx_plugin_info ipx_plugin_info = {
19+
// Plugin identification name
20+
"tcp",
21+
// Brief description of the plugin
22+
"Input plugins for IPFIX/NetFlow v5/v9 over Transmission Control Protocol.",
23+
// Plugin type (input plugin)
24+
IPX_PT_INPUT,
25+
// Configuration flags (unused)
26+
0,
27+
// Plugin version string
28+
"3.0.0",
29+
// Minimal IPFIXcol version string
30+
"2.0.0",
31+
};
32+
33+
using namespace tcp_in;
34+
35+
int ipx_plugin_init(ipx_ctx_t *ctx, const char *params) {
36+
Plugin *plugin;
37+
38+
try {
39+
Config conf(ctx, params);
40+
plugin = new Plugin(ctx, conf);
41+
} catch (std::exception &ex) {
42+
IPX_CTX_ERROR(ctx, "%s", ex.what());
43+
return IPX_ERR_DENIED;
44+
}
45+
46+
ipx_ctx_private_set(ctx, plugin);
47+
return IPX_OK;
48+
}
49+
50+
int ipx_plugin_get(ipx_ctx_t *ctx, void *cfg) {
51+
auto plugin = reinterpret_cast<Plugin *>(cfg);
52+
53+
try {
54+
plugin->get();
55+
} catch (std::exception &ex) {
56+
IPX_CTX_ERROR(ctx, "%s", ex.what());
57+
return IPX_ERR_DENIED;
58+
}
59+
60+
return IPX_OK;
61+
}
62+
63+
void ipx_plugin_session_close(ipx_ctx_t *ctx, void *cfg, const struct ipx_session *session) {
64+
auto plugin = reinterpret_cast<Plugin *>(cfg);
65+
66+
try {
67+
plugin->close_session(session);
68+
} catch (std::exception &ex) {
69+
IPX_CTX_ERROR(ctx, "%s", ex.what());
70+
}
71+
}
72+
73+
void ipx_plugin_destroy(ipx_ctx_t *ctx, void *cfg) {
74+
(void)ctx;
75+
delete reinterpret_cast<Plugin *>(cfg);
76+
}

0 commit comments

Comments
 (0)