]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow tag: conversion to flow storage API
authorEric Leblond <eric@regit.org>
Wed, 20 Mar 2013 10:28:58 +0000 (11:28 +0100)
committerVictor Julien <victor@inliniac.net>
Sun, 28 Jul 2013 21:41:11 +0000 (23:41 +0200)
This patch is updating the flow tag system to use the flow
storage API. The tag_list member of Flow structure is suppressed
and its cleaning operation are suppressed too as this is handled
transparently by the flow storage API.

src/detect-engine-tag.c
src/flow-util.h
src/flow.h

index 59db17d4e2142782be14f5e153f6a53b23123b29..53207882c0cd5a239bee3278dc5873df0b583be3 100644 (file)
 #include "detect-tag.h"
 #include "host.h"
 #include "host-storage.h"
+#include "flow-storage.h"
 
 SC_ATOMIC_DECLARE(unsigned int, num_tags);  /**< Atomic counter, to know if we
                                                  have tagged hosts/sessions,
                                                  to avoid locking */
 static int tag_id = 0;                      /**< Host storage id for tags */
+static int flow_tag_id = 0;                 /**< Flow storage id for tags */
 
 void TagInitCtx(void) {
     SC_ATOMIC_INIT(num_tags);
 
     tag_id = HostStorageRegister("tag", sizeof(void *), NULL, DetectTagDataListFree);
+    flow_tag_id = FlowStorageRegister("tag", sizeof(void *), NULL, DetectTagDataListFree);
 }
 
 /**
@@ -111,10 +114,8 @@ int TagFlowAdd(Packet *p, DetectTagDataEntry *tde) {
         return 1;
 
     FLOWLOCK_WRLOCK(p->flow);
-
-    if (p->flow->tag_list != NULL) {
-        iter = p->flow->tag_list;
-
+    iter = FlowGetStorageById(p->flow, flow_tag_id);
+    if (iter != NULL) {
         /* First iterate installed entries searching a duplicated sid/gid */
         for (; iter != NULL; iter = iter->next) {
             num_tags++;
@@ -140,8 +141,8 @@ int TagFlowAdd(Packet *p, DetectTagDataEntry *tde) {
     if (updated == 0 && num_tags < DETECT_TAG_MAX_TAGS) {
         DetectTagDataEntry *new_tde = DetectTagDataCopy(tde);
         if (new_tde != NULL) {
-            new_tde->next = p->flow->tag_list;
-            p->flow->tag_list = new_tde;
+            new_tde->next = FlowGetStorageById(p->flow, flow_tag_id);
+            FlowSetStorageById(p->flow, flow_tag_id, new_tde);
             (void) SC_ATOMIC_ADD(num_tags, 1);
         }
     } else if (num_tags == DETECT_TAG_MAX_TAGS) {
@@ -232,12 +233,12 @@ int TagHashAddTag(DetectTagDataEntry *tde, Packet *p)
 }
 
 static void TagHandlePacketFlow(Flow *f, Packet *p) {
-    if (f->tag_list == NULL)
+    if (FlowGetStorageById(f, flow_tag_id) == NULL)
         return;
 
     DetectTagDataEntry *tde = NULL;
     DetectTagDataEntry *prev = NULL;
-    DetectTagDataEntry *iter = f->tag_list;
+    DetectTagDataEntry *iter = FlowGetStorageById(f, flow_tag_id);
     uint8_t flag_added = 0;
 
     while (iter != NULL) {
@@ -270,7 +271,7 @@ static void TagHandlePacketFlow(Flow *f, Packet *p) {
                             (void) SC_ATOMIC_SUB(num_tags, 1);
                             continue;
                         } else {
-                            p->flow->tag_list = iter->next;
+                            FlowSetStorageById(p->flow, flow_tag_id, iter->next);
                             tde = iter;
                             iter = iter->next;
                             SCFree(tde);
@@ -295,7 +296,7 @@ static void TagHandlePacketFlow(Flow *f, Packet *p) {
                             (void) SC_ATOMIC_SUB(num_tags, 1);
                             continue;
                         } else {
-                            p->flow->tag_list = iter->next;
+                            FlowSetStorageById(p->flow, flow_tag_id, iter->next);
                             tde = iter;
                             iter = iter->next;
                             SCFree(tde);
@@ -322,7 +323,7 @@ static void TagHandlePacketFlow(Flow *f, Packet *p) {
                             (void) SC_ATOMIC_SUB(num_tags, 1);
                             continue;
                         } else {
-                            p->flow->tag_list = iter->next;
+                            FlowSetStorageById(p->flow, flow_tag_id, iter->next);
                             tde = iter;
                             iter = iter->next;
                             SCFree(tde);
index ef7d8de878f26507c0525d4d06c944df98caabab..09a177c8450e8e251f4f0c9b06db82a6ef1e4535 100644 (file)
@@ -56,7 +56,6 @@
         (f)->de_state = NULL; \
         (f)->sgh_toserver = NULL; \
         (f)->sgh_toclient = NULL; \
-        (f)->tag_list = NULL; \
         (f)->flowvar = NULL; \
         SCMutexInit(&(f)->de_state_m, NULL); \
         (f)->hnext = NULL; \
@@ -92,8 +91,6 @@
         } \
         (f)->sgh_toserver = NULL; \
         (f)->sgh_toclient = NULL; \
-        DetectTagDataListFree((f)->tag_list); \
-        (f)->tag_list = NULL; \
         GenericVarFree((f)->flowvar); \
         (f)->flowvar = NULL; \
         if (SC_ATOMIC_GET((f)->autofp_tmqh_flow_qid) != -1) {   \
         if ((f)->de_state != NULL) { \
             DetectEngineStateFree((f)->de_state); \
         } \
-        DetectTagDataListFree((f)->tag_list); \
         GenericVarFree((f)->flowvar); \
         SCMutexDestroy(&(f)->de_state_m); \
         SC_ATOMIC_DESTROY((f)->autofp_tmqh_flow_qid);   \
-        (f)->tag_list = NULL; \
     } while(0)
 
 /** \brief check if a memory alloc would fit in the memcap
index aa6311d00b088bed693b6ff73533da3c3cf13adc..2afe4f8bf3492b80a6941c4079f2822033a42699 100644 (file)
@@ -342,9 +342,6 @@ typedef struct Flow_
      *  has been set. */
     struct SigGroupHead_ *sgh_toserver;
 
-    /** List of tags of this flow (from "tag" keyword of type "session") */
-    void *tag_list;
-
     /* pointer to the var list */
     GenericVar *flowvar;