Skip to content

Commit 34870c7

Browse files
AdamZvarasedmicha
authored andcommitted
ASN, GeoIP: skip option template records
1 parent 18d9d69 commit 34870c7

File tree

2 files changed

+100
-38
lines changed

2 files changed

+100
-38
lines changed

src/plugins/intermediate/asn/asn.c

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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
279279
estimate_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
304304
ipfix_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
348348
ipfix_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
}

src/plugins/intermediate/geoip/geoip.c

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,39 @@ ipfix_start_builder(ipx_ctx_t *ctx, ipx_msg_builder_t *builder,
470470
return IPX_OK;
471471
}
472472

473+
/**
474+
* \brief Add record to new message in builder
475+
*
476+
* \param[in] ctx Plugin context
477+
* \param[in] builder Message builder
478+
* \param[in] rec Data record
479+
* \return
480+
*/
481+
static int
482+
add_record_to_builder(ipx_ctx_t *ctx, ipx_msg_builder_t *builder, const struct fds_drec *rec)
483+
{
484+
// Store modified record in builder
485+
int rc = ipx_msg_builder_add_drec(builder, rec);
486+
487+
if (rc) {
488+
switch(rc) {
489+
case IPX_ERR_DENIED:
490+
// Exceeded builder limit
491+
IPX_CTX_ERROR(ctx, "Exceeded message builder limit", __FILE__, __LINE__);
492+
return rc;
493+
case IPX_ERR_NOMEM:
494+
IPX_CTX_ERROR(ctx, "Memory allocation error (%s:%d)", __FILE__, __LINE__);
495+
return rc;
496+
default:
497+
IPX_CTX_ERROR(ctx, "Unexpected error from ipx_modifier_add_session (%s:%d)",
498+
__FILE__, __LINE__);
499+
return rc;
500+
}
501+
}
502+
503+
return IPX_OK;
504+
}
505+
473506
/**
474507
* \brief Process IPFIX message
475508
*
@@ -512,6 +545,15 @@ process_ipfix(ipx_ctx_t *ctx, ipx_modifier_t *modifier, ipx_msg_builder_t *build
512545
for (uint32_t i = 0; i < rec_cnt; i++) {
513546
rec = ipx_msg_ipfix_get_drec(msg, i);
514547

548+
if (rec->rec.tmplt->type == FDS_TYPE_TEMPLATE_OPTS) {
549+
// Options template found ... just add it into new message
550+
if (add_record_to_builder(ctx, builder, &(rec->rec)) != IPX_OK) {
551+
// Error ... proper message has been already printed
552+
return rc;
553+
}
554+
continue;
555+
}
556+
515557
// Modify record
516558
modified_rec = ipx_modifier_modify(modifier, &(rec->rec), &ipfix_garbage);
517559
if (ipfix_garbage) {
@@ -522,24 +564,13 @@ process_ipfix(ipx_ctx_t *ctx, ipx_modifier_t *modifier, ipx_msg_builder_t *build
522564
return IPX_ERR_DENIED;
523565
}
524566

525-
// Store modified record in builder
526-
rc = ipx_msg_builder_add_drec(builder, modified_rec);
527-
528-
if (rc) {
529-
switch(rc) {
530-
case IPX_ERR_DENIED:
531-
// Exceeded builder limit
532-
IPX_CTX_ERROR(ctx, "Exceeded message builder limit", __FILE__, __LINE__);
533-
return rc;
534-
case IPX_ERR_NOMEM:
535-
IPX_CTX_ERROR(ctx, "Memory allocation error (%s:%d)", __FILE__, __LINE__);
536-
return rc;
537-
default:
538-
IPX_CTX_ERROR(ctx, "Unexpected error from ipx_modifier_add_session (%s:%d)",
539-
__FILE__, __LINE__);
540-
return rc;
541-
}
567+
// Add modified record to new message
568+
rc = add_record_to_builder(ctx, builder, modified_rec);
569+
if (rc != IPX_OK) {
570+
// Error ... proper message has been already printed
571+
return rc;
542572
}
573+
543574
free(modified_rec->data);
544575
free(modified_rec);
545576
}

0 commit comments

Comments
 (0)