]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow id: quick and dirty first stab at a flow id
authorVictor Julien <victor@inliniac.net>
Wed, 4 Jun 2014 11:37:02 +0000 (13:37 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 28 Jul 2014 13:47:45 +0000 (15:47 +0200)
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
src/output-json-netflow.c
src/output-json.c
src/output-json.h

index 91623f14faa5ce2008f35c7aa671878703f6e365..107e4ffe8930c3ea003870925afbf41b5c617b69 100644 (file)
@@ -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)
index 30d799536af5d0b6ceaea87670dad3a57963efb0..a7d54c8b9ddca1e7ad28e05205c23bc02c524f4b 100644 (file)
@@ -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)
index 3fd5500066b452b620f7e285cb05e1fb758b08fb..2bcca89d835d9ee859fd8ae54f2de80d17ff8474 100644 (file)
@@ -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));
index 418c9de1b8847d33d79fcc7832be1ef6049479f0..e35b81be4581fa51d0deb5daf432dce4419818bd 100644 (file)
@@ -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);