From f1185d051c210ca0daacdddbe865a51af24f4ea3 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Wed, 4 Jun 2014 13:37:02 +0200 Subject: [PATCH] flow id: quick and dirty first stab at a flow id Add a 'flow_id' that is the same for all records produced for packets belonging to the same flow. This patch simply takes the flow's memory address. --- src/output-json-flow.c | 3 +++ src/output-json-netflow.c | 3 +++ src/output-json.c | 14 ++++++++++++++ src/output-json.h | 1 + 4 files changed, 21 insertions(+) diff --git a/src/output-json-flow.c b/src/output-json-flow.c index 91623f14fa..107e4ffe89 100644 --- a/src/output-json-flow.c +++ b/src/output-json-flow.c @@ -107,6 +107,9 @@ static json_t *CreateJSONHeaderFromFlow(Flow *f, char *event_type) /* time */ json_object_set_new(js, "timestamp", json_string(timebuf)); + + CreateJSONFlowId(js, (const Flow *)f); + #if 0 // TODO /* sensor id */ if (sensor_id >= 0) diff --git a/src/output-json-netflow.c b/src/output-json-netflow.c index 30d799536a..a7d54c8b9d 100644 --- a/src/output-json-netflow.c +++ b/src/output-json-netflow.c @@ -116,6 +116,9 @@ static json_t *CreateJSONHeaderFromFlow(Flow *f, char *event_type, int dir) /* time */ json_object_set_new(js, "timestamp", json_string(timebuf)); + + CreateJSONFlowId(js, (const Flow *)f); + #if 0 // TODO /* sensor id */ if (sensor_id >= 0) diff --git a/src/output-json.c b/src/output-json.c index 3fd5500066..2bcca89d83 100644 --- a/src/output-json.c +++ b/src/output-json.c @@ -169,6 +169,18 @@ void JsonTcpFlags(uint8_t flags, json_t *js) { json_object_set_new(js, "cwr", json_true()); } +void CreateJSONFlowId(json_t *js, const Flow *f) +{ + if (f == NULL) + return; +#if __WORDSIZE == 64 + uint64_t addr = (uint64_t)f; +#else + uint32_t addr = (uint32_t)f; +#endif + json_object_set_new(js, "flow_id", json_integer(addr)); +} + json_t *CreateJSONHeader(Packet *p, int direction_sensitive, char *event_type) { char timebuf[64]; @@ -227,6 +239,8 @@ json_t *CreateJSONHeader(Packet *p, int direction_sensitive, char *event_type) /* time & tx */ json_object_set_new(js, "timestamp", json_string(timebuf)); + CreateJSONFlowId(js, (const Flow *)p->flow); + /* sensor id */ if (sensor_id >= 0) json_object_set_new(js, "sensor_id", json_integer(sensor_id)); diff --git a/src/output-json.h b/src/output-json.h index 418c9de1b8..e35b81be45 100644 --- a/src/output-json.h +++ b/src/output-json.h @@ -32,6 +32,7 @@ void TmModuleOutputJsonRegister (void); #include "util-buffer.h" #include "util-logopenfile.h" +void CreateJSONFlowId(json_t *js, const Flow *f); void JsonTcpFlags(uint8_t flags, json_t *js); json_t *CreateJSONHeader(Packet *p, int direction_sensative, char *event_type); TmEcode OutputJSON(json_t *js, void *data, uint64_t *count);