@@ -275,7 +275,7 @@ process_session(ipx_ctx_t *ctx, ipx_modifier_t *modifier, ipx_msg_session_t *msg
275275 * \param[in] msg IPFIX message
276276 * \return Estimated size
277277 */
278- int
278+ static inline int
279279estimate_new_length (ipx_msg_ipfix_t * msg )
280280{
281281 const struct fds_ipfix_msg_hdr * hdr = (struct fds_ipfix_msg_hdr * ) ipx_msg_ipfix_get_packet (msg );
@@ -300,7 +300,7 @@ estimate_new_length(ipx_msg_ipfix_t *msg)
300300 * \return #IPX_ERR_ARG on invalid arguments
301301 * \return #IPX_ERR_NOMEM on memory allocation error
302302 */
303- int
303+ static int
304304ipfix_add_session (ipx_ctx_t * ctx , ipx_modifier_t * modifier , ipx_msg_ipfix_t * msg )
305305{
306306 int rc ;
@@ -344,7 +344,7 @@ ipfix_add_session(ipx_ctx_t *ctx, ipx_modifier_t *modifier, ipx_msg_ipfix_t *msg
344344 * \return #IPX_ERR_ARG on invalid arguments
345345 * \return #IPX_ERR_NOMEM on memory allocation error
346346 */
347- int
347+ static int
348348ipfix_start_builder (ipx_ctx_t * ctx , ipx_msg_builder_t * builder ,
349349 const struct fds_ipfix_msg_hdr * hdr , const size_t maxsize )
350350{
@@ -369,6 +369,39 @@ ipfix_start_builder(ipx_ctx_t *ctx, ipx_msg_builder_t *builder,
369369 return IPX_OK ;
370370}
371371
372+ /**
373+ * \brief Add record to new message in builder
374+ *
375+ * \param[in] ctx Plugin context
376+ * \param[in] builder Message builder
377+ * \param[in] rec Data record
378+ * \return
379+ */
380+ static int
381+ add_record_to_builder (ipx_ctx_t * ctx , ipx_msg_builder_t * builder , const struct fds_drec * rec )
382+ {
383+ // Store modified record in builder
384+ int rc = ipx_msg_builder_add_drec (builder , rec );
385+
386+ if (rc ) {
387+ switch (rc ) {
388+ case IPX_ERR_DENIED :
389+ // Exceeded builder limit
390+ IPX_CTX_ERROR (ctx , "Exceeded message builder limit" , __FILE__ , __LINE__ );
391+ return rc ;
392+ case IPX_ERR_NOMEM :
393+ IPX_CTX_ERROR (ctx , "Memory allocation error (%s:%d)" , __FILE__ , __LINE__ );
394+ return rc ;
395+ default :
396+ IPX_CTX_ERROR (ctx , "Unexpected error from ipx_modifier_add_session (%s:%d)" ,
397+ __FILE__ , __LINE__ );
398+ return rc ;
399+ }
400+ }
401+
402+ return IPX_OK ;
403+ }
404+
372405/**
373406 * \brief Process IPFIX message
374407 *
@@ -411,34 +444,32 @@ process_ipfix(ipx_ctx_t *ctx, ipx_modifier_t *modifier, ipx_msg_builder_t *build
411444 for (uint32_t i = 0 ; i < rec_cnt ; i ++ ) {
412445 rec = ipx_msg_ipfix_get_drec (msg , i );
413446
447+ if (rec -> rec .tmplt -> type == FDS_TYPE_TEMPLATE_OPTS ) {
448+ // Options template found ... just add it into new message
449+ if (add_record_to_builder (ctx , builder , & (rec -> rec )) != IPX_OK ) {
450+ // Error ... proper message has been already printed
451+ return rc ;
452+ }
453+ continue ;
454+ }
455+
414456 // Modify record
415457 modified_rec = ipx_modifier_modify (modifier , & (rec -> rec ), & ipfix_garbage );
416458 if (ipfix_garbage ) {
417459 ipx_ctx_msg_pass (ctx , ipx_msg_garbage2base (ipfix_garbage ));
418460 }
419461 if (!modified_rec ) {
420- // Proper message has been already printed
462+ // Error ... proper message has been already printed
421463 return IPX_ERR_DENIED ;
422464 }
423465
424- // Store modified record in builder
425- rc = ipx_msg_builder_add_drec (builder , modified_rec );
426-
427- if (rc ) {
428- switch (rc ) {
429- case IPX_ERR_DENIED :
430- // Exceeded builder limit
431- IPX_CTX_ERROR (ctx , "Exceeded message builder limit" , __FILE__ , __LINE__ );
432- return rc ;
433- case IPX_ERR_NOMEM :
434- IPX_CTX_ERROR (ctx , "Memory allocation error (%s:%d)" , __FILE__ , __LINE__ );
435- return rc ;
436- default :
437- IPX_CTX_ERROR (ctx , "Unexpected error from ipx_modifier_add_session (%s:%d)" ,
438- __FILE__ , __LINE__ );
439- return rc ;
440- }
466+ // Add modified record to new message
467+ rc = add_record_to_builder (ctx , builder , modified_rec );
468+ if (rc != IPX_OK ) {
469+ // Error ... proper message has been already printed
470+ return rc ;
441471 }
472+
442473 free (modified_rec -> data );
443474 free (modified_rec );
444475 }
0 commit comments