Skip to content

Commit 7750095

Browse files
committed
Core: polishing support for Data Record extensions
1 parent c6c9718 commit 7750095

File tree

4 files changed

+26
-43
lines changed

4 files changed

+26
-43
lines changed

include/ipfixcol2/plugins.h

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -467,38 +467,30 @@ IPX_API int
467467
ipx_ctx_ext_consumer(ipx_ctx_t *ctx, const char *type, const char *name, ipx_ctx_ext_t **ext);
468468

469469
/**
470-
* \brief Get size of an extension
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.
471475
*
472-
* Information about the extension are not available during ipx_plugin_init().
473476
* \param[in] ext Internal description of the extension
474-
* \param[out] size Size 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)
475480
* \return #IPX_OK on success
476-
* \return #IPX_ERR_DENIED if the information is not available
481+
* \return #IPX_ERR_NOTFOUND if the extension hasn't been filled by its producer
477482
*/
478483
IPX_API int
479-
ipx_ctx_ext_size(ipx_ctx_ext_t *ext, size_t *size);
480-
481-
/**
482-
* \brief Get data of an extension
483-
*
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
488-
* \param[in] ipx_drec Data Record with extensions
489-
* \return Pointer to the extension or NULL
490-
*/
491-
IPX_API void *
492-
ipx_ctx_ext_get(ipx_ctx_ext_t *ext, struct ipx_ipfix_record *ipx_drec);
484+
ipx_ctx_ext_get(ipx_ctx_ext_t *ext, struct ipx_ipfix_record *drec, void **data, size_t *size);
493485

494486
/**
495487
* \brief Set the extension of a Data Record as filled (ONLY for the producer of the extension)
496488
*
497-
* \param[in] ext Internal description of the extension
498-
* \param[in] ipx_drec Data Record with extensions
489+
* \param[in] ext Internal description of the extension
490+
* \param[in] drec Data Record with extensions
499491
*/
500492
IPX_API void
501-
ipx_ctx_ext_set_filled(ipx_ctx_ext_t *ext, struct ipx_ipfix_record *ipx_drec);
493+
ipx_ctx_ext_set_filled(ipx_ctx_ext_t *ext, struct ipx_ipfix_record *drec);
502494

503495
/**
504496
* @}

src/core/configurator/extensions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ ipx_cfg_extensions::check_dependencies(const std::string &ident, const struct ex
9898

9999
// No producers?
100100
if (rec.producers.empty()) {
101-
throw std::runtime_error("No provider of Data Record extension " + ident + "found. "
101+
throw std::runtime_error("No provider of Data Record extension " + ident + " found. "
102102
"The extension is required by " + name_consumers);
103103
}
104104

@@ -122,7 +122,7 @@ ipx_cfg_extensions::check_dependencies(const std::string &ident, const struct ex
122122
throw std::runtime_error("Instance '" + producer_rec.name + "', which is a provider "
123123
"of Data Record extension " + ident + ", is placed in the collector pipeline "
124124
"after '" + min_cons->name + "' instance, which depends on the extension. "
125-
"Please, swap the order of the plugin instances");
125+
"Please, swap the order of the plugin instances.");
126126
}
127127
}
128128

@@ -176,8 +176,8 @@ ipx_cfg_extensions::resolve()
176176
ext.mask = mask;
177177

178178
// Align the offset to multiple of 8
179-
ext.offset += (ext.size % 8U == 0) ? (ext.size) : (((ext.size / 8U) + 1U) * 8U);
180-
ext.mask <<= 1U;
179+
offset += (ext.size % 8U == 0) ? (ext.size) : (((ext.size / 8U) + 1U) * 8U);
180+
mask <<= 1U;
181181
}
182182
}
183183

src/core/context.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ ipx_ctx_init(ipx_ctx_t *ctx, const char *params)
719719
// Try to initialize the plugin
720720
const char *plugin_name = ctx->plugin_cbs->info->name;
721721
IPX_CTX_DEBUG(ctx, "Calling instance constructor of the plugin '%s'", plugin_name);
722+
ctx->type = plugin_type;
722723
// Temporarily remove permission to pass messages
723724
uint32_t permissions_old = ctx->permissions;
724725
ctx->permissions &= ~(uint32_t) IPX_CP_MSG_PASS;
@@ -732,6 +733,7 @@ ipx_ctx_init(ipx_ctx_t *ctx, const char *params)
732733
if (rc != IPX_OK) {
733734
IPX_CTX_ERROR(ctx, "Initialization function of the instance failed!", '\0');
734735
// Restore default default parameters
736+
ctx->type = 0;
735737
ctx->permissions = 0;
736738
ctx->cfg_system.msg_mask_selected = 0;
737739
ctx->cfg_system.msg_mask_allowed = IPX_MSG_IPFIX | IPX_MSG_SESSION;
@@ -746,7 +748,6 @@ ipx_ctx_init(ipx_ctx_t *ctx, const char *params)
746748
IPX_CTX_WARNING(ctx, "The instance didn't set its private data.", '\0');
747749
}
748750

749-
ctx->type = plugin_type;
750751
ctx->state = IPX_CS_INIT;
751752
return IPX_OK;
752753
}

src/core/extension.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,36 +45,26 @@
4545
#include <string.h>
4646

4747
int
48-
ipx_ctx_ext_size(ipx_ctx_ext_t *ext, size_t *size)
48+
ipx_ctx_ext_get(ipx_ctx_ext_t *ext, struct ipx_ipfix_record *drec, void **data, size_t *size)
4949
{
50-
if (!ext->mask) {
51-
// Mask is not filled -> initialization hasn't been completed yet
52-
return IPX_ERR_DENIED;
50+
if (ext->etype == IPX_EXTENSION_CONSUMER && (drec->ext_mask & ext->mask) == 0) {
51+
// The extension hasn't been filled by the producer
52+
return IPX_ERR_NOTFOUND;
5353
}
5454

55+
*data = &drec->ext[ext->offset];
5556
*size = ext->size;
5657
return IPX_OK;
5758
}
5859

59-
void *
60-
ipx_ctx_ext_get(ipx_ctx_ext_t *ext, struct ipx_ipfix_record *ipx_drec)
61-
{
62-
if (ext->etype == IPX_EXTENSION_CONSUMER && (ipx_drec->ext_mask & ext->mask) == 0) {
63-
// The extension hasn't been filled by the producer
64-
return NULL;
65-
}
66-
67-
return (ipx_drec->ext + ext->offset);
68-
}
69-
7060
void
71-
ipx_ctx_ext_set_filled(ipx_ctx_ext_t *ext, struct ipx_ipfix_record *ipx_drec)
61+
ipx_ctx_ext_set_filled(ipx_ctx_ext_t *ext, struct ipx_ipfix_record *drec)
7262
{
7363
if (ext->etype != IPX_EXTENSION_PRODUCER) {
7464
return; // Not allowed!
7565
}
7666

77-
ipx_drec->ext_mask |= ext->mask;
67+
drec->ext_mask |= ext->mask;
7868
}
7969

8070
int

0 commit comments

Comments
 (0)