flowbits: allow setter to know if set is new

pull/12931/head
Victor Julien 4 years ago committed by Victor Julien
parent 2921d07b1b
commit 062e58103e

@ -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)

@ -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);

Loading…
Cancel
Save