]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flowbits: allow setter to know if set is new
authorVictor Julien <vjulien@oisf.net>
Mon, 10 Oct 2022 09:42:02 +0000 (11:42 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 3 Apr 2025 08:05:43 +0000 (10:05 +0200)
src/flow-bit.c
src/flow-bit.h

index 304e6bd41569b79780af6705c1c4f6a796d97a98..f481220e64b686706c143773b0ee21247b33271f 100644 (file)
@@ -55,19 +55,25 @@ static FlowBit *FlowBitGet(Flow *f, uint32_t idx)
     return NULL;
 }
 
-/* add a flowbit to the flow */
-static void FlowBitAdd(Flow *f, uint32_t idx)
+/** \brief add a flowbit to the flow
+ *  \retval -1 error
+ *  \retval 0 not added, already set before
+ *  \retval 1 added */
+static int FlowBitAdd(Flow *f, uint32_t idx)
 {
     FlowBit *fb = FlowBitGet(f, idx);
     if (fb == NULL) {
         fb = SCMalloc(sizeof(FlowBit));
         if (unlikely(fb == NULL))
-            return;
+            return -1;
 
         fb->type = DETECT_FLOWBITS;
         fb->idx = idx;
         fb->next = NULL;
         GenericVarAppend(&f->flowvar, (GenericVar *)fb);
+        return 1;
+    } else {
+        return 0;
     }
 }
 
@@ -81,9 +87,13 @@ static void FlowBitRemove(Flow *f, uint32_t idx)
     FlowBitFree(fb);
 }
 
-void FlowBitSet(Flow *f, uint32_t idx)
+/** \brief add a flowbit to the flow
+ *  \retval -1 error
+ *  \retval 0 not added, already set before
+ *  \retval 1 added */
+int FlowBitSet(Flow *f, uint32_t idx)
 {
-    FlowBitAdd(f, idx);
+    return FlowBitAdd(f, idx);
 }
 
 void FlowBitUnset(Flow *f, uint32_t idx)
index c98fa585cd52bce5ea5811a475a83b51a26ea743..c7c32e776fa74cc9a3cc3a952818e6fe2a6327dd 100644 (file)
@@ -39,7 +39,7 @@ typedef struct FlowBit_ {
 void FlowBitFree(FlowBit *);
 void FlowBitRegisterTests(void);
 
-void FlowBitSet(Flow *, uint32_t);
+int FlowBitSet(Flow *, uint32_t);
 void FlowBitUnset(Flow *, uint32_t);
 bool FlowBitToggle(Flow *, uint32_t);
 int FlowBitIsset(Flow *, uint32_t);