|
| 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