@@ -957,9 +957,9 @@ mgr_store_template(ipx_modifier_t *mod, struct fds_template *tmplt, fds_tgarbage
957957 * \brief Add template to mapper, print error line if failed
958958 */
959959static inline void
960- mapper_add_template (ipx_modifier_t * mod , const struct fds_template * tmplt , uint16_t original_id )
960+ mapper_add_template (ipx_modifier_t * mod , const struct fds_template * tmplt , struct modified_tmplt_id * item , uint16_t original_id )
961961{
962- if (ipx_mapper_add (mod -> curr_ctx -> mapper , tmplt , original_id ) != IPX_OK ) {
962+ if (ipx_mapper_add (mod -> curr_ctx -> mapper , tmplt , item , original_id ) != IPX_OK ) {
963963 // Could not add mapping
964964 MODIFIER_WARNING (mod , "Could not add mapping for template ID %u (ODID: %d)" ,
965965 original_id , mod -> curr_ctx -> odid );
@@ -1006,8 +1006,8 @@ aux_template_store_garbage_destroy(struct aux_template_store_garbage *gb)
10061006 * \param[out] garbage Potential garbage from modifier context
10071007 * \return Pointer to stored template or NULL if error occurred
10081008 */
1009- static const struct fds_template *
1010- template_store (ipx_modifier_t * mod , struct fds_template * tmplt , uint16_t original_id , ipx_msg_garbage_t * * garbage )
1009+ static struct fds_template *
1010+ template_store (ipx_modifier_t * mod , struct fds_template * tmplt , uint16_t original_id , ipx_msg_garbage_t * * garbage , struct modified_tmplt_id * item )
10111011{
10121012 int rc ;
10131013 fds_tgarbage_t * mapper_garbage = NULL ;
@@ -1029,7 +1029,9 @@ template_store(ipx_modifier_t *mod, struct fds_template *tmplt, uint16_t origina
10291029
10301030 if (mgr_tmplt ) {
10311031 // Template exists in manager, add mapping
1032- mapper_add_template (mod , mgr_tmplt , original_id );
1032+ mapper_add_template (mod , mgr_tmplt , item , original_id );
1033+ // Destroy modified template
1034+ fds_template_destroy (tmplt );
10331035 return mgr_tmplt ;
10341036 }
10351037
@@ -1041,10 +1043,12 @@ template_store(ipx_modifier_t *mod, struct fds_template *tmplt, uint16_t origina
10411043 }
10421044
10431045 // Add new mapping
1044- mapper_add_template (mod , tmplt , original_id );
1046+ mapper_add_template (mod , tmplt , item , original_id );
10451047
10461048 // If any garbage was generated, create garbage message from it
10471049 if (mapper_garbage || context_garbage ) {
1050+ // Clear mapper
1051+ ipx_mapper_clear (mod -> curr_ctx -> mapper );
10481052 struct aux_template_store_garbage * gb = malloc (sizeof (* gb ));
10491053 if (gb == NULL ) {
10501054 MODIFIER_ERROR (mod , "Memory allocation failed (%s:%d)" , __FILE__ , __LINE__ );
@@ -1119,6 +1123,26 @@ fields_update(struct fds_drec *rec, ipx_modifier_t *mod, struct ipx_modifier_out
11191123 return IPX_OK ;
11201124}
11211125
1126+ static inline void
1127+ output_buffer2id (const struct ipx_modifier_output * output , size_t fields_cnt , struct modified_tmplt_id * id )
1128+ {
1129+ uint8_t appended_fields [fields_cnt ];
1130+
1131+ /** Convert fields to array, which will be stored in modified_tmplt_id*/
1132+ for (uint16_t i = 0 ; i < fields_cnt ; ++ i ) {
1133+ if (output [i ].length >= 0 ) {
1134+ appended_fields [i ] = 1 ;
1135+ } else if (output [i ].length == IPX_MODIFIER_SKIP ) {
1136+ appended_fields [i ] = 0 ;
1137+ } else {
1138+ appended_fields [i ] = -1 ;
1139+ }
1140+ }
1141+
1142+ memcpy (id -> appended_fields , appended_fields , fields_cnt );
1143+ }
1144+
1145+
11221146struct fds_drec *
11231147ipx_modifier_modify (ipx_modifier_t * mod , const struct fds_drec * rec , ipx_msg_garbage_t * * garbage )
11241148{
@@ -1132,6 +1156,7 @@ ipx_modifier_modify(ipx_modifier_t *mod, const struct fds_drec *rec, ipx_msg_gar
11321156 return NULL ;
11331157 }
11341158
1159+ struct fds_template * new_tmplt = NULL ;
11351160 * garbage = NULL ;
11361161
11371162 // Create filter array
@@ -1155,36 +1180,41 @@ ipx_modifier_modify(ipx_modifier_t *mod, const struct fds_drec *rec, ipx_msg_gar
11551180 }
11561181 }
11571182
1158- // Update template based on modified configuration
1159- struct fds_template * new_tmplt = template_update (rec -> tmplt , mod , buffers , filter );
1160- if (!new_tmplt ) {
1161- MODIFIER_ERROR (mod , "Failed to update template (%s:%d)" , __FILE__ , __LINE__ );
1162- return NULL ;
1163- }
1183+ // Create array which will be used to identify modified template
1184+ struct modified_tmplt_id mod_identifier = {0 };
1185+ output_buffer2id (buffers , mod -> fields_cnt , & mod_identifier );
1186+ mod_identifier .data = rec -> tmplt -> raw .data ;
1187+ mod_identifier .length = rec -> tmplt -> raw .length ;
11641188
11651189 // Try to search for modified template in modifier mapper
1166- const struct fds_template * map_tmplt = ipx_mapper_lookup (mod -> curr_ctx -> mapper , new_tmplt , rec -> tmplt -> id );
1190+ const struct fds_template * map_tmplt = ipx_mapper_lookup (mod -> curr_ctx -> mapper , & mod_identifier , rec -> tmplt -> id );
11671191 if (map_tmplt ) {
11681192 // Mapping found, free modified template and use template found in mapper
1169- fds_template_destroy (new_tmplt );
11701193 new_tmplt = (struct fds_template * ) map_tmplt ;
11711194 } else {
11721195 // Mapping not found, need to store modified template in manager
1173- const struct fds_template * stored_tmplt = template_store (mod , new_tmplt , rec -> tmplt -> id , garbage );
1196+ new_tmplt = template_update (rec -> tmplt , mod , buffers , filter );
1197+ if (!new_tmplt ) {
1198+ MODIFIER_ERROR (mod , "Failed to update template (%s:%d)" , __FILE__ , __LINE__ );
1199+ return NULL ;
1200+ }
1201+
1202+ struct fds_template * stored_tmplt = template_store (mod , new_tmplt , rec -> tmplt -> id , garbage , & mod_identifier );
11741203
11751204 if (!stored_tmplt ) {
11761205 // Error message has been generated
11771206 fds_template_destroy (new_tmplt );
11781207 return NULL ;
11791208 }
1209+
1210+ new_tmplt = stored_tmplt ;
11801211 }
11811212
11821213 // Fetch current snapshot
11831214 const fds_tsnapshot_t * snap ;
11841215 get_current_snapshot (mod , & snap );
11851216 if (!snap ) {
11861217 // Error message has been generated
1187- // DO NOT free modified template as it is stored in modifier
11881218 return NULL ;
11891219 }
11901220
@@ -1201,7 +1231,6 @@ ipx_modifier_modify(ipx_modifier_t *mod, const struct fds_drec *rec, ipx_msg_gar
12011231 if (fields_update (new_rec , mod , buffers , filter ) != IPX_OK ) {
12021232 MODIFIER_ERROR (mod , "Failed to update fields in record (%s:%d)" , __FILE__ , __LINE__ );
12031233 free (new_rec );
1204- // DO NOT free modified template, as it is stored in modifier
12051234 return NULL ;
12061235 }
12071236
0 commit comments