@@ -586,16 +586,7 @@ ipfix_template_add_field(const struct ipx_modifier_field field, uint16_t *raw)
586586 assert (false);
587587}
588588
589- /**
590- * \brief Append new fields to template based on given output values
591- *
592- * \param[in] tmplt Original template
593- * \param[in] fields Array of new fields
594- * \param[in] buffers Array of output values
595- * \param[in] fields_cnt Number of items in fields (and buffers) array
596- * \return Parsed modified template or NULL (memory allocation error)
597- */
598- static struct fds_template *
589+ struct fds_template *
599590ipfix_template_add_fields (const struct fds_template * tmplt ,
600591 const struct ipx_modifier_field * fields ,
601592 const struct ipx_modifier_output * buffers ,
@@ -636,20 +627,7 @@ ipfix_template_add_fields(const struct fds_template *tmplt,
636627 return new_tmplt ;
637628}
638629
639- /**
640- * \brief Append new fields to data record
641- *
642- * \note Variable length fields will contain 1 or 3 length prefix octets
643- * based on their length in output buffer. For length < 255 single prefix octet
644- * is used. Otherwise 3 octets are used.
645- *
646- * \param[in,out] rec Original/modified record
647- * \param[in] fields Field definitions
648- * \param[in] output Output buffers containing new values
649- * \param[in] arr_cnt Size of output buffer
650- * \return #IPX_OK on success, otherwise #IPX_ERR_NOMEM
651- */
652- static int
630+ int
653631ipfix_msg_add_drecs (struct fds_drec * rec ,
654632 const struct ipx_modifier_field * fields ,
655633 const struct ipx_modifier_output * output ,
@@ -669,7 +647,7 @@ ipfix_msg_add_drecs(struct fds_drec *rec,
669647 if (output [i ].length == IPX_MODIFIER_SKIP ) {
670648 // Skip field
671649 continue ;
672- } else if (output [i ].length < 0 ) {
650+ } else if (output [i ].length <= 0 ) {
673651 // Dont copy memory from buffer, but keep this field
674652
675653 if (fields [i ].length == FDS_IPFIX_VAR_IE_LEN ) {
@@ -710,16 +688,7 @@ ipfix_msg_add_drecs(struct fds_drec *rec,
710688 return IPX_OK ;
711689}
712690
713- /**
714- * \brief Remove fields from template based on given filter
715- *
716- * \warning Only non-option templates are accepted.
717- *
718- * \param[in] tmplt Original template
719- * \param[in] filter Filter array
720- * \return Parsed modified template or NULL (memory allocation error)
721- */
722- static struct fds_template *
691+ struct fds_template *
723692ipfix_template_remove_fields (const struct fds_template * tmplt , const uint8_t * filter )
724693{
725694 assert (tmplt -> type == FDS_TYPE_TEMPLATE );
@@ -787,16 +756,7 @@ ipfix_template_remove_fields(const struct fds_template *tmplt, const uint8_t *fi
787756 return new_template ;
788757}
789758
790- /**
791- * \brief Remove fields from data record based on filter
792- *
793- * Filter is an array of integers for each field in record template. For each
794- * non-zero value in filter, data field at same position is removed from message.
795- *
796- * \param[in,out] rec Original record
797- * \param[in] filter Filter array
798- */
799- static void
759+ void
800760ipfix_msg_remove_drecs (struct fds_drec * rec , const uint8_t * filter )
801761{
802762 uint16_t filter_size = rec -> tmplt -> fields_cnt_total ;
@@ -825,7 +785,8 @@ ipfix_msg_remove_drecs(struct fds_drec *rec, const uint8_t *filter)
825785 rec_size -= it .field .size + length_octets ;
826786 }
827787 prev_rec = it .field .data + it .field .size ;
828- assert (idx ++ < filter_size );
788+ idx ++ ;
789+ assert (idx <= filter_size );
829790 }
830791
831792 // Go through filter in reverse order and delete selected records
@@ -839,54 +800,6 @@ ipfix_msg_remove_drecs(struct fds_drec *rec, const uint8_t *filter)
839800 rec -> size = rec_size ;
840801}
841802
842- int
843- ipx_modifier_filter (struct fds_drec * rec , uint8_t * filter )
844- {
845- if (rec == NULL || filter == NULL ) {
846- return IPX_ERR_ARG ;
847- }
848-
849- // Modify template
850- struct fds_template * tmplt = ipfix_template_remove_fields (rec -> tmplt , filter );
851- if (tmplt == NULL ) {
852- return IPX_ERR_NOMEM ;
853- }
854-
855- // Modify record
856- ipfix_msg_remove_drecs (rec , filter );
857- rec -> tmplt = tmplt ;
858- rec -> snap = NULL ;
859-
860- return IPX_OK ;
861- }
862-
863- int
864- ipx_modifier_append (struct fds_drec * rec ,
865- const struct ipx_modifier_field * fields ,
866- const struct ipx_modifier_output * buffers ,
867- const size_t fields_cnt )
868- {
869- if (rec == NULL || fields == NULL || buffers == NULL ) {
870- return IPX_ERR_ARG ;
871- }
872-
873- // Modify template
874- struct fds_template * tmplt = ipfix_template_add_fields (rec -> tmplt , fields , buffers , fields_cnt );
875- if (tmplt == NULL ) {
876- return IPX_ERR_NOMEM ;
877- }
878-
879- // Modify record
880- if (ipfix_msg_add_drecs (rec , fields , buffers , fields_cnt ) != IPX_OK ) {
881- fds_template_destroy (tmplt );
882- return IPX_ERR_NOMEM ;
883- }
884- rec -> tmplt = tmplt ;
885- rec -> snap = NULL ;
886-
887- return IPX_OK ;
888- }
889-
890803/**
891804 * \brief Generate and set new ID for template
892805 *
@@ -976,7 +889,7 @@ template_store(ipx_modifier_t *mod, struct fds_drec *rec, ipx_msg_garbage_t **ga
976889 * \param[out] garbage Possible garbage created in this function
977890 * \return #IPX_OK on success, #IPX_ERR_NOMEM on memory allocation error
978891 */
979- int
892+ static int
980893template_modify_and_store (struct fds_drec * rec , ipx_modifier_t * mod , struct ipx_modifier_output * output , uint8_t * filter , ipx_msg_garbage_t * * garbage )
981894{
982895 struct fds_template * new_tmplt = (struct fds_template * ) rec -> tmplt ;
@@ -1022,7 +935,7 @@ template_modify_and_store(struct fds_drec *rec, ipx_modifier_t *mod, struct ipx_
1022935 * \param[out] new_output Array of valid values
1023936 * \param[in] output_cnt Number of output buffer elements
1024937 */
1025- void
938+ static inline void
1026939output_buffer_to_array (struct ipx_modifier_output * output , uint8_t * new_output , size_t output_cnt )
1027940{
1028941 for (size_t i = 0 ; i < output_cnt ; ++ i ) {
@@ -1034,7 +947,17 @@ output_buffer_to_array(struct ipx_modifier_output *output, uint8_t *new_output,
1034947 }
1035948}
1036949
1037- int
950+ /**
951+ * \brief Update appended/filtered fields in template
952+ *
953+ * \param[in] rec Pointer to data record
954+ * \param[in] mod Modifier
955+ * \param[in] output Output buffers
956+ * \param[in] filter Filter array
957+ * \param[out] garbage Possible garbage created in this function
958+ * \return #IPX_OK on success, #IPX_ERR_NOMEM on memory allocation error
959+ */
960+ static int
1038961template_update (struct fds_drec * rec , ipx_modifier_t * mod , struct ipx_modifier_output * output , uint8_t * filter , ipx_msg_garbage_t * * garbage )
1039962{
1040963 const struct fds_template * tmplt = rec -> tmplt ;
@@ -1085,7 +1008,7 @@ template_update(struct fds_drec *rec, ipx_modifier_t *mod, struct ipx_modifier_o
10851008 * \param[in] filter Filter array
10861009 * \return #IPX_OK on success, #IPX_ERR_NOMEM on memory allocation error
10871010 */
1088- int
1011+ static int
10891012fields_update (struct fds_drec * rec , ipx_modifier_t * mod , struct ipx_modifier_output * output , uint8_t * filter )
10901013{
10911014 if (mod -> cb_filter ) {
0 commit comments