Skip to content

Commit e6b052b

Browse files
AdamZvarasedmicha
authored andcommitted
ASN: fix finding AS number for IPv6
1 parent e855e01 commit e6b052b

File tree

1 file changed

+27
-27
lines changed
  • src/plugins/intermediate/asn

1 file changed

+27
-27
lines changed

src/plugins/intermediate/asn/asn.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,6 @@
4646

4747
#define ASN_LOOKUP_STRING "autonomous_system_number"
4848

49-
/** Plugin description */
50-
IPX_API struct ipx_plugin_info ipx_plugin_info = {
51-
// Plugin type
52-
.type = IPX_PT_INTERMEDIATE,
53-
// Plugin identification name
54-
.name = "asn",
55-
// Brief description of plugin
56-
.dsc = "IPv4/IPv6 autonomous system number (ASN) module",
57-
// Configuration flags (reserved for future use)
58-
.flags = 0,
59-
// Plugin version string (like "1.2.3")
60-
.version = "2.0.0",
61-
// Minimal IPFIXcol version string (like "1.2.3")
62-
.ipx_min = "2.3.0"
63-
};
64-
6549
/** Instance */
6650
struct instance_data {
6751
/** Parsed configuration of the instance */
@@ -155,7 +139,7 @@ get_asn(MMDB_s *db, struct ipx_modifier_output *out, uint8_t *address, size_t le
155139
.sin_addr.s_addr = *((uint32_t *)address)
156140
};
157141
addr = (struct sockaddr *) &addr_4;
158-
} else if (length == 6) {
142+
} else if (length == 16) {
159143
// IPv6 address
160144
struct sockaddr_in6 addr_6 = {
161145
.sin6_family = AF_INET6
@@ -221,11 +205,11 @@ modifier_asn_callback(const struct fds_drec *rec, struct ipx_modifier_output out
221205
if (fds_drec_find((struct fds_drec *)rec, 0, 12, &field) != FDS_EOC) {
222206
// IPv4
223207
assert(field.size == 4);
224-
get_asn(db, &output[ASN_DST], field.data, 4);
208+
rc = get_asn(db, &output[ASN_DST], field.data, 4);
225209
} else if (fds_drec_find((struct fds_drec *)rec, 0, 28, &field) != FDS_EOC) {
226210
// IPv6
227211
assert(field.size == 16);
228-
get_asn(db, &output[ASN_DST], field.data, 16);
212+
rc = get_asn(db, &output[ASN_DST], field.data, 16);
229213
}
230214

231215
if (rc) {
@@ -238,8 +222,7 @@ modifier_asn_callback(const struct fds_drec *rec, struct ipx_modifier_output out
238222
/**
239223
* \brief Process session message
240224
*
241-
* In the event of closing session, information about the particular
242-
* Transport Session will be removed.
225+
* In the event of closing session, information about the particular Transport Session will be removed.
243226
* \param[in] ctx Plugin context
244227
* \param[in] modifier Modifier component
245228
* \param[in] msg Transport session message
@@ -257,18 +240,19 @@ process_session(ipx_ctx_t *ctx, ipx_modifier_t *modifier, ipx_msg_session_t *msg
257240
int rc;
258241
const struct ipx_session *session = ipx_msg_session_get_session(msg);
259242

243+
// Always pass the original session message
244+
ipx_ctx_msg_pass(ctx, ipx_msg_session2base(msg));
245+
260246
ipx_msg_garbage_t *garbage;
261247
if ((rc = ipx_modifier_remove_session(modifier, session, &garbage)) == IPX_OK) {
262-
// No error occured, pass the original message
263-
ipx_ctx_msg_pass(ctx, ipx_msg_session2base(msg));
264-
265-
/* Send garbage after session message because other plugins might have references to
266-
templates linked to that session */
248+
// Again, possible memory leak
267249
if (garbage == NULL) {
268250
IPX_CTX_WARNING(ctx, "A memory allocation failed (%s:%d).", __FILE__, __LINE__);
269251
return IPX_OK;
270252
}
271253

254+
/* Send garbage after session message because other plugins might have references to
255+
templates linked to that session */
272256
ipx_ctx_msg_pass(ctx, ipx_msg_garbage2base(garbage));
273257
return IPX_OK;
274258
}
@@ -491,6 +475,22 @@ process_ipfix(ipx_ctx_t *ctx, ipx_modifier_t *modifier, ipx_msg_builder_t *build
491475

492476
// -------------------------------------------------------------------------------------------------
493477

478+
/** Plugin description */
479+
IPX_API struct ipx_plugin_info ipx_plugin_info = {
480+
// Plugin type
481+
.type = IPX_PT_INTERMEDIATE,
482+
// Plugin identification name
483+
.name = "asn",
484+
// Brief description of plugin
485+
.dsc = "IPv4/IPv6 autonomous system number (ASN) module",
486+
// Configuration flags (reserved for future use)
487+
.flags = 0,
488+
// Plugin version string (like "1.2.3")
489+
.version = "2.0.0",
490+
// Minimal IPFIXcol version string (like "1.2.3")
491+
.ipx_min = "2.3.0"
492+
};
493+
494494
int
495495
ipx_plugin_init(ipx_ctx_t *ctx, const char *params)
496496
{
@@ -604,4 +604,4 @@ ipx_plugin_process(ipx_ctx_t *ctx, void *cfg, ipx_msg_t *msg)
604604
}
605605

606606
return IPX_OK;
607-
}
607+
}

0 commit comments

Comments
 (0)