22 * \file include/ipfixcol2/plugins.h
33 * \author Lukas Hutak <[email protected] > 44 * \brief IPFIXcol plugin interface and functions (header file)
5- * \date 2018
5+ * \date 2018-2020
66 */
77
8- /* Copyright (C) 2018 CESNET, z.s.p.o.
8+ /* Copyright (C) 2018-2020 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
@@ -49,12 +49,13 @@ extern "C" {
4949/** Internal plugin context */
5050typedef struct ipx_ctx ipx_ctx_t ;
5151/** 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 ;
5353
5454#include <ipfixcol2/api.h>
5555#include <ipfixcol2/verbose.h>
5656#include <ipfixcol2/session.h>
5757#include <ipfixcol2/message.h>
58+ #include <ipfixcol2/message_ipfix.h>
5859
5960/**
6061 * \defgroup pluginAPI Plugin API
@@ -397,7 +398,7 @@ IPX_API const fds_iemgr_t *
397398ipx_ctx_iemgr_get (ipx_ctx_t * ctx );
398399
399400/**
400- * \brief Register an extension of Data Records (Intermediate and Output plugins ONLY!)
401+ * \brief Register an extension of Data Records (Intermediate plugins ONLY!)
401402 *
402403 * Reserve space for metadata that will be part of each Data Record. The purpose of extension
403404 * it is to add non-flow information which can be useful during record processing. For example,
@@ -406,28 +407,32 @@ ipx_ctx_iemgr_get(ipx_ctx_t *ctx);
406407 *
407408 * Structure or data type of the extension is up to the producer. Nevertheless, the producer and
408409 * all consumers must use the same. The producer is also RESPONSIBLE for filling content of the
409- * extension to EACH Data Record in the IPFIX Message!
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.
410413 *
411414 * One plugin instance can register multiple extensions.
412415 * \warning
413- * This function can be called only during ipx_plugin_init() of Intermediate and Output plugins.
416+ * This function can be called only during ipx_plugin_init() of Intermediate plugins.
414417 * \note
415418 * Only single plugin instance at time can produce extension with the given combination
416419 * of the \p type and the \p name.
417420 * \param[in] ctx Plugin context
418421 * \param[in] type Identification of the extension type (e.g. "profiles-v1")
419422 * \param[in] name Identification of the extension name (e.g. "main_profiles")
420- * \param[in] size Size of memory required for the extension (in bytes)
421- * \param[out] rext Internal description of the extension
423+ * \param[in] size Non-zero size of memory required for the extension (in bytes)
424+ * \param[out] ext Internal description of the extension
422425 *
423426 * \return #IPX_OK on success
424- * \return #IPX_ERR_ARG if the \p type or \p name are not valid (i.e. empty or NULL)
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.
425429 * \return #IPX_ERR_DENIED if the plugin doesn't have permission to register extension
426- * \return #IPX_ERR_NOMEM if the maximum number of extensions has been reached
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
427432 */
428433IPX_API int
429- ipx_ctx_rext_producer (ipx_ctx_t * ctx , const char * type , const char * name , size_t size ,
430- ipx_ctx_rext * * rext );
434+ ipx_ctx_ext_producer (ipx_ctx_t * ctx , const char * type , const char * name , size_t size ,
435+ ipx_ctx_ext_t * * ext );
431436
432437/**
433438 * @brief Add dependency on an extension of Data Records (Intermediate and Output plugins ONLY!)
@@ -450,37 +455,50 @@ ipx_ctx_rext_producer(ipx_ctx_t *ctx, const char *type, const char *name, size_t
450455 * \param[in] ctx Plugin context
451456 * \param[in] type Identification of the extension type (e.g. "profiles-v1")
452457 * \param[in] name Identification of the extension name (e.g. "main_profiles")
453- * \param[out] rext Internal description of the extension
458+ * \param[out] ext Internal description of the extension
454459 *
455460 * \return #IPX_OK on success (see notes)
456461 * \return #IPX_ERR_ARG if the \p type or \p name are not valid (i.e. empty or NULL)
457462 * \return #IPX_ERR_DENIED if the plugin doesn't have permission to register dependency
458- * \return #IPX_ERR_NOMEM if the maximum number of extensions has been reached
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
459465 */
460466IPX_API int
461- ipx_ctx_rext_consumer (ipx_ctx_t * ctx , const char * type , const char * name , ipx_ctx_rext_t * * rext );
467+ ipx_ctx_ext_consumer (ipx_ctx_t * ctx , const char * type , const char * name , ipx_ctx_ext_t * * ext );
462468
463469/**
464470 * \brief Get size of an extension
465471 *
466472 * Information about the extension are not available during ipx_plugin_init().
467- * \param[in] rext Internal description of the extension
473+ * \param[in] ext Internal description of the extension
468474 * \param[out] size Size of the extension
469475 * \return #IPX_OK on success
470476 * \return #IPX_ERR_DENIED if the information is not available
471477 */
472478IPX_API int
473- ipx_ctx_rext_size ( ipx_ctx_rext * rext , size_t * size );
479+ ipx_ctx_ext_size ( ipx_ctx_ext_t * ext , size_t * size );
474480
475481/**
476482 * \brief Get data of an extension
477483 *
478- * \param[in] rext Internal description of the extension
484+ * \note
485+ * In case of a consumer, the function can return NULL if the extension hasn't been filled
486+ * by the producer!
487+ * \param[in] ext Internal description of the extension
479488 * \param[in] ipx_drec Data Record with extensions
480- * \return Pointer to the extension
489+ * \return Pointer to the extension or NULL
481490 */
482491IPX_API void *
483- ipx_ctx_rext_get (ipx_ctx_rext * rext , struct ipx_ipfix_record * ipx_drec );
492+ ipx_ctx_ext_get (ipx_ctx_ext_t * ext , struct ipx_ipfix_record * ipx_drec );
493+
494+ /**
495+ * \brief Set the extension of a Data Record as filled (ONLY for the producer of the extension)
496+ *
497+ * \param[in] ext Internal description of the extension
498+ * \param[in] ipx_drec Data Record with extensions
499+ */
500+ IPX_API void
501+ ipx_ctx_ext_set_filled (ipx_ctx_ext_t * ext , struct ipx_ipfix_record * ipx_drec );
484502
485503/**
486504 * @}
0 commit comments