Skip to content

Commit 2dc4b25

Browse files
committed
IPFIX parser: fixed invalid order of pipeline messages passing in case of a Transport Session disconnection
1 parent e32c8f4 commit 2dc4b25

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

src/core/plugin_parser.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,37 +118,46 @@ ipx_plugin_parser_destroy(ipx_ctx_t *ctx, void *cfg)
118118
*
119119
* If the event is of close type, information about the particular Transport Session will be
120120
* removed, i.e. all template managers and counters of sequence numbers.
121-
* \param[in] ctx Plugin context
122-
* \param[in] parser IPFIX Message parser
123-
* \param[in] msg Transport Session message
121+
* \param[in] ctx Plugin context
122+
* \param[in] parser IPFIX Message parser
123+
* \param[in] msg_session Transport Session message
124124
* \return Always #IPX_OK
125125
*/
126126
static inline int
127-
parser_plugin_process_session(ipx_ctx_t *ctx, ipx_parser_t *parser, ipx_msg_session_t *msg)
127+
parser_plugin_process_session(ipx_ctx_t *ctx, ipx_parser_t *parser, ipx_msg_session_t *msg_session)
128128
{
129-
if (ipx_msg_session_get_event(msg) != IPX_MSG_SESSION_CLOSE) {
129+
if (ipx_msg_session_get_event(msg_session) != IPX_MSG_SESSION_CLOSE) {
130130
// Ignore non-close events
131+
ipx_ctx_msg_pass(ctx, ipx_msg_session2base(msg_session));
131132
return IPX_OK;
132133
}
133134

134135
int rc;
135-
const struct ipx_session *session = ipx_msg_session_get_session(msg);
136+
const struct ipx_session *session = ipx_msg_session_get_session(msg_session);
137+
138+
ipx_msg_garbage_t *msg_garbage;
139+
if ((rc = ipx_parser_session_remove(parser, session, &msg_garbage)) == IPX_OK) {
140+
// Everything is fine, pass the message(s)
141+
ipx_ctx_msg_pass(ctx, ipx_msg_session2base(msg_session));
136142

137-
ipx_msg_garbage_t *g_msg;
138-
if ((rc = ipx_parser_session_remove(parser, session, &g_msg)) == IPX_OK) {
139-
// Send garbage
140-
if (g_msg == NULL) {
143+
/* Send garbage
144+
* Garbage MUST be send after the Transport Session (TS) Message because other plugins can
145+
* have references to the templates linked to this TS. Otherwise there is a chance that
146+
* any template that is present in the garbage message is dereferenced by the plugins.
147+
*/
148+
if (msg_garbage == NULL) {
141149
IPX_CTX_WARNING(ctx, "A memory allocation failed (%s:%d).", __FILE__, __LINE__);
142150
return IPX_OK;
143151
}
144152

145-
ipx_ctx_msg_pass(ctx, ipx_msg_garbage2base(g_msg));
153+
ipx_ctx_msg_pass(ctx, ipx_msg_garbage2base(msg_garbage));
146154
return IPX_OK;
147155
}
148156

157+
// Possible internal errors
149158
switch (rc) {
150159
case IPX_ERR_NOTFOUND:
151-
IPX_CTX_WARNING(ctx, "Received an event about closing of unknown Transport Session '%s'.",
160+
IPX_CTX_ERROR(ctx, "Received an event about closing of unknown Transport Session '%s'.",
152161
session->ident);
153162
break;
154163
default:
@@ -157,6 +166,8 @@ parser_plugin_process_session(ipx_ctx_t *ctx, ipx_parser_t *parser, ipx_msg_sess
157166
break;
158167
}
159168

169+
// In case of an internal error always pass the TS message
170+
ipx_ctx_msg_pass(ctx, ipx_msg_session2base(msg_session));
160171
return IPX_OK;
161172
}
162173

@@ -286,7 +297,6 @@ ipx_plugin_parser_process(ipx_ctx_t *ctx, void *cfg, ipx_msg_t *msg)
286297
case IPX_MSG_SESSION:
287298
// Process Transport Session
288299
rc = parser_plugin_process_session(ctx, parser, ipx_msg_base2session(msg));
289-
ipx_ctx_msg_pass(ctx, msg);
290300
break;
291301
default:
292302
// Unexpected type of the message

0 commit comments

Comments
 (0)