From: Victor Julien Date: Mon, 10 Oct 2022 09:42:02 +0000 (+0200) Subject: flowbits: allow setter to know if set is new X-Git-Tag: suricata-8.0.0-beta1~86 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=062e58103eff021a60c28afe4aaa6f31de43c9ea;p=thirdparty%2Fsuricata.git flowbits: allow setter to know if set is new --- diff --git a/src/flow-bit.c b/src/flow-bit.c index 304e6bd415..f481220e64 100644 --- a/src/flow-bit.c +++ b/src/flow-bit.c @@ -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) diff --git a/src/flow-bit.h b/src/flow-bit.h index c98fa585cd..c7c32e776f 100644 --- a/src/flow-bit.h +++ b/src/flow-bit.h @@ -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);