From: Victor Julien Date: Mon, 22 Apr 2013 15:48:51 +0000 (+0200) Subject: flowvar/flowint: split set functions into normal and NoLock version, where the latter... X-Git-Tag: suricata-2.0beta1~129 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c3c3cd76e5c0e920c2be9e58f137c937f6e1d79e;p=thirdparty%2Fsuricata.git flowvar/flowint: split set functions into normal and NoLock version, where the latter won't lock the flow. --- diff --git a/src/flow-var.c b/src/flow-var.c index 0a38b35f51..d70dcad3b7 100644 --- a/src/flow-var.c +++ b/src/flow-var.c @@ -45,9 +45,10 @@ static void FlowVarUpdateInt(FlowVar *fv, uint32_t value) { fv->data.fv_int.value = value; } -/* get the flowvar with name 'name' from the flow - * - * name is a normal string*/ +/** \brief get the flowvar with index 'idx' from the flow + * \note flow is not locked by this function, caller is + * responsible + */ FlowVar *FlowVarGet(Flow *f, uint16_t idx) { GenericVar *gv = f->flowvar; @@ -60,14 +61,12 @@ FlowVar *FlowVarGet(Flow *f, uint16_t idx) { } /* add a flowvar to the flow, or update it */ -void FlowVarAddStr(Flow *f, uint16_t idx, uint8_t *value, uint16_t size) { - FLOWLOCK_WRLOCK(f); - +void FlowVarAddStrNoLock(Flow *f, uint16_t idx, uint8_t *value, uint16_t size) { FlowVar *fv = FlowVarGet(f, idx); if (fv == NULL) { fv = SCMalloc(sizeof(FlowVar)); if (unlikely(fv == NULL)) - goto out; + return; fv->type = DETECT_FLOWVAR; fv->datatype = FLOWVAR_TYPE_STR; @@ -80,20 +79,22 @@ void FlowVarAddStr(Flow *f, uint16_t idx, uint8_t *value, uint16_t size) { } else { FlowVarUpdateStr(fv, value, size); } - -out: - FLOWLOCK_UNLOCK(f); } /* add a flowvar to the flow, or update it */ -void FlowVarAddInt(Flow *f, uint16_t idx, uint32_t value) { +void FlowVarAddStr(Flow *f, uint16_t idx, uint8_t *value, uint16_t size) { FLOWLOCK_WRLOCK(f); + FlowVarAddStrNoLock(f, idx, value, size); + FLOWLOCK_UNLOCK(f); +} +/* add a flowvar to the flow, or update it */ +void FlowVarAddIntNoLock(Flow *f, uint16_t idx, uint32_t value) { FlowVar *fv = FlowVarGet(f, idx); if (fv == NULL) { fv = SCMalloc(sizeof(FlowVar)); if (unlikely(fv == NULL)) - goto out; + return; fv->type = DETECT_FLOWVAR; fv->datatype = FLOWVAR_TYPE_INT; @@ -105,8 +106,12 @@ void FlowVarAddInt(Flow *f, uint16_t idx, uint32_t value) { } else { FlowVarUpdateInt(fv, value); } +} -out: +/* add a flowvar to the flow, or update it */ +void FlowVarAddInt(Flow *f, uint16_t idx, uint32_t value) { + FLOWLOCK_WRLOCK(f); + FlowVarAddIntNoLock(f, idx, value); FLOWLOCK_UNLOCK(f); } @@ -143,7 +148,7 @@ void FlowVarPrint(GenericVar *gv) { } SCLogDebug("\", Len \"%" PRIu16 "\"\n", fv->data.fv_str.value_len); } else if (fv->datatype == FLOWVAR_TYPE_INT) { - SCLogDebug("Name idx \"%" PRIu16 "\", Value \"%" PRIu16 "\"", fv->idx, + SCLogDebug("Name idx \"%" PRIu16 "\", Value \"%" PRIu32 "\"", fv->idx, fv->data.fv_int.value); } else { SCLogDebug("Unknown data type at flowvars\n"); diff --git a/src/flow-var.h b/src/flow-var.h index 2621c05e1b..cd3e42cdb0 100644 --- a/src/flow-var.h +++ b/src/flow-var.h @@ -61,7 +61,9 @@ typedef struct FlowVar_ { /** Flowvar Interface API */ +void FlowVarAddStrNoLock(Flow *, uint16_t, uint8_t *, uint16_t); void FlowVarAddStr(Flow *, uint16_t, uint8_t *, uint16_t); +void FlowVarAddIntNoLock(Flow *, uint16_t, uint32_t); void FlowVarAddInt(Flow *, uint16_t, uint32_t); FlowVar *FlowVarGet(Flow *, uint16_t); void FlowVarFree(FlowVar *);