|
2 | 2 | * \file include/ipfixcol2/plugins.h |
3 | 3 | * \author Lukas Hutak <[email protected]> |
4 | 4 | * \brief IPFIXcol plugin interface and functions (header file) |
5 | | - * \date 2018 |
| 5 | + * \date 2018-2020 |
6 | 6 | */ |
7 | 7 |
|
8 | | -/* Copyright (C) 2018 CESNET, z.s.p.o. |
| 8 | +/* Copyright (C) 2018-2020 CESNET, z.s.p.o. |
9 | 9 | * |
10 | 10 | * Redistribution and use in source and binary forms, with or without |
11 | 11 | * modification, are permitted provided that the following conditions |
@@ -49,12 +49,13 @@ extern "C" { |
49 | 49 | /** Internal plugin context */ |
50 | 50 | typedef struct ipx_ctx ipx_ctx_t; |
51 | 51 | /** Internal data structure that represents IPFIXcol record extension */ |
52 | | -typedef struct ipx_ctx_rext ipx_ctx_rext_t; |
| 52 | +typedef struct ipx_ctx_ext ipx_ctx_ext_t; |
53 | 53 |
|
54 | 54 | #include <ipfixcol2/api.h> |
55 | 55 | #include <ipfixcol2/verbose.h> |
56 | 56 | #include <ipfixcol2/session.h> |
57 | 57 | #include <ipfixcol2/message.h> |
| 58 | +#include <ipfixcol2/message_ipfix.h> |
58 | 59 |
|
59 | 60 | /** |
60 | 61 | * \defgroup pluginAPI Plugin API |
@@ -396,6 +397,101 @@ ipx_ctx_subscribe(ipx_ctx_t *ctx, const ipx_msg_mask_t *mask_new, ipx_msg_mask_t |
396 | 397 | IPX_API const fds_iemgr_t * |
397 | 398 | ipx_ctx_iemgr_get(ipx_ctx_t *ctx); |
398 | 399 |
|
| 400 | +/** |
| 401 | + * \brief Register an extension of Data Records (Intermediate plugins ONLY!) |
| 402 | + * |
| 403 | + * Reserve space for metadata that will be part of each Data Record. The purpose of extension |
| 404 | + * it is to add non-flow information which can be useful during record processing. For example, |
| 405 | + * one plugin can add some labels and one or more plugins further in the pipeline can use them |
| 406 | + * later. |
| 407 | + * |
| 408 | + * Structure or data type of the extension is up to the producer. Nevertheless, the producer and |
| 409 | + * all consumers must use the same. The producer is also RESPONSIBLE for filling content of the |
| 410 | + * extension to EACH Data Record in the IPFIX Message! After filling the extension, function |
| 411 | + * ipx_ctx_ext_set_filled() must be called to mark the extension memory as filled. Otherwise, |
| 412 | + * consumers are not able get its content. |
| 413 | + * |
| 414 | + * One plugin instance can register multiple extensions. |
| 415 | + * \warning |
| 416 | + * This function can be called only during ipx_plugin_init() of Intermediate plugins. |
| 417 | + * \note |
| 418 | + * Only single plugin instance at time can produce extension with the given combination |
| 419 | + * of the \p type and the \p name. |
| 420 | + * \param[in] ctx Plugin context |
| 421 | + * \param[in] type Identification of the extension type (e.g. "profiles-v1") |
| 422 | + * \param[in] name Identification of the extension name (e.g. "main_profiles") |
| 423 | + * \param[in] size Non-zero size of memory required for the extension (in bytes) |
| 424 | + * \param[out] ext Internal description of the extension |
| 425 | + * |
| 426 | + * \return #IPX_OK on success |
| 427 | + * \return #IPX_ERR_ARG if the \p type or \p name are not valid (i.e. empty or NULL) or \p size |
| 428 | + * is zero. |
| 429 | + * \return #IPX_ERR_DENIED if the plugin doesn't have permission to register extension |
| 430 | + * \return #IPX_ERR_EXISTS if the extension or dependency has been already registered by this plugin |
| 431 | + * \return #IPX_ERR_NOMEM if a memory allocation failure has occurred |
| 432 | + */ |
| 433 | +IPX_API int |
| 434 | +ipx_ctx_ext_producer(ipx_ctx_t *ctx, const char *type, const char *name, size_t size, |
| 435 | + ipx_ctx_ext_t **ext); |
| 436 | + |
| 437 | +/** |
| 438 | + * @brief Add dependency on an extension of Data Records (Intermediate and Output plugins ONLY!) |
| 439 | + * |
| 440 | + * Register dependency on an extension. This will make sure that the required extension is |
| 441 | + * available for EACH Data Record during ipx_plugin_process() and that there is a particular |
| 442 | + * producer earlier in the processing pipeline. |
| 443 | + * |
| 444 | + * One plugin instance can register multiple dependencies. |
| 445 | + * |
| 446 | + * \warning |
| 447 | + * This function can be called only during ipx_plugin_init() of Intermediate and Output plugins. |
| 448 | + * \note |
| 449 | + * If the function has succeeded, it doesn't mean that there is particular extension producer. |
| 450 | + * Since dependencies are resolved later during configuration of the collector, startup |
| 451 | + * process will be interrupted if all requirements are not met. |
| 452 | + * \note |
| 453 | + * The plugin instance CANNOT add dependency on an extension which it is producing. |
| 454 | + * |
| 455 | + * \param[in] ctx Plugin context |
| 456 | + * \param[in] type Identification of the extension type (e.g. "profiles-v1") |
| 457 | + * \param[in] name Identification of the extension name (e.g. "main_profiles") |
| 458 | + * \param[out] ext Internal description of the extension |
| 459 | + * |
| 460 | + * \return #IPX_OK on success (see notes) |
| 461 | + * \return #IPX_ERR_ARG if the \p type or \p name are not valid (i.e. empty or NULL) |
| 462 | + * \return #IPX_ERR_DENIED if the plugin doesn't have permission to register dependency |
| 463 | + * \return #IPX_ERR_EXISTS if the dependency or extension has been already registered by this plugin |
| 464 | + * \return #IPX_ERR_NOMEM if a memory allocation failure has occurred |
| 465 | + */ |
| 466 | +IPX_API int |
| 467 | +ipx_ctx_ext_consumer(ipx_ctx_t *ctx, const char *type, const char *name, ipx_ctx_ext_t **ext); |
| 468 | + |
| 469 | +/** |
| 470 | + * \brief Get an extension |
| 471 | + * |
| 472 | + * In case of a producer of the extension, it always returns #IPX_OK and fills the pointer and |
| 473 | + * size. If the producer decides to fill the extension, it also must call ipx_ctx_ext_set_filled(). |
| 474 | + * Otherwise, consumers will not be able to get its content. |
| 475 | + * |
| 476 | + * \param[in] ext Internal description of the extension |
| 477 | + * \param[in] drec Data Record with extensions |
| 478 | + * \param[out] data Pointer to extension data |
| 479 | + * \param[out] size Size of the extensions (bytes) |
| 480 | + * \return #IPX_OK on success |
| 481 | + * \return #IPX_ERR_NOTFOUND if the extension hasn't been filled by its producer |
| 482 | + */ |
| 483 | +IPX_API int |
| 484 | +ipx_ctx_ext_get(ipx_ctx_ext_t *ext, struct ipx_ipfix_record *drec, void **data, size_t *size); |
| 485 | + |
| 486 | +/** |
| 487 | + * \brief Set the extension of a Data Record as filled (ONLY for the producer of the extension) |
| 488 | + * |
| 489 | + * \param[in] ext Internal description of the extension |
| 490 | + * \param[in] drec Data Record with extensions |
| 491 | + */ |
| 492 | +IPX_API void |
| 493 | +ipx_ctx_ext_set_filled(ipx_ctx_ext_t *ext, struct ipx_ipfix_record *drec); |
| 494 | + |
399 | 495 | /** |
400 | 496 | * @} |
401 | 497 | * @} |
|
0 commit comments