diff --git a/src/detect-lua-extensions.c b/src/detect-lua-extensions.c index 44a8cfd216..6bd5c2453b 100644 --- a/src/detect-lua-extensions.c +++ b/src/detect-lua-extensions.c @@ -80,7 +80,6 @@ static int LuaGetFlowvar(lua_State *luastate) Flow *f; FlowVar *fv; DetectLuaData *ld; - int flow_lock = 0; /* need luajit data for id -> idx conversion */ lua_pushlightuserdata(luastate, (void *)&luaext_key_ld); @@ -94,7 +93,7 @@ static int LuaGetFlowvar(lua_State *luastate) } /* need flow and lock hint */ - f = LuaStateGetFlow(luastate, &flow_lock); + f = LuaStateGetFlow(luastate); if (f == NULL) { lua_pushnil(luastate); lua_pushstring(luastate, "no flow"); @@ -120,15 +119,8 @@ static int LuaGetFlowvar(lua_State *luastate) return 2; } - /* lookup var */ - if (flow_lock == LUA_FLOW_NOT_LOCKED_BY_PARENT) - FLOWLOCK_RDLOCK(f); - fv = FlowVarGet(f, idx); if (fv == NULL) { - if (flow_lock == LUA_FLOW_NOT_LOCKED_BY_PARENT) - FLOWLOCK_UNLOCK(f); - lua_pushnil(luastate); lua_pushstring(luastate, "no flow var"); return 2; @@ -137,9 +129,6 @@ static int LuaGetFlowvar(lua_State *luastate) LuaPushStringBuffer(luastate, (const uint8_t *)fv->data.fv_str.value, (size_t)fv->data.fv_str.value_len); - if (flow_lock == LUA_FLOW_NOT_LOCKED_BY_PARENT) - FLOWLOCK_UNLOCK(f); - return 1; } @@ -154,7 +143,6 @@ int LuaSetFlowvar(lua_State *luastate) uint8_t *buffer; DetectEngineThreadCtx *det_ctx; DetectLuaData *ld; - int flow_lock = 0; /* need luajit data for id -> idx conversion */ lua_pushlightuserdata(luastate, (void *)&luaext_key_ld); @@ -179,7 +167,7 @@ int LuaSetFlowvar(lua_State *luastate) } /* need flow and lock hint */ - f = LuaStateGetFlow(luastate, &flow_lock); + f = LuaStateGetFlow(luastate); if (f == NULL) { lua_pushnil(luastate); lua_pushstring(luastate, "no flow"); @@ -239,10 +227,7 @@ int LuaSetFlowvar(lua_State *luastate) memcpy(buffer, str, len); buffer[len] = '\0'; - if (flow_lock == LUA_FLOW_NOT_LOCKED_BY_PARENT) - FlowVarAddStr(f, idx, buffer, len); - else - FlowVarAddStrNoLock(f, idx, buffer, len); + FlowVarAddStr(f, idx, buffer, len); //SCLogInfo("stored:"); //PrintRawDataFp(stdout,buffer,len); @@ -256,7 +241,6 @@ static int LuaGetFlowint(lua_State *luastate) Flow *f; FlowVar *fv; DetectLuaData *ld; - int flow_lock = 0; uint32_t number; /* need luajit data for id -> idx conversion */ @@ -271,7 +255,7 @@ static int LuaGetFlowint(lua_State *luastate) } /* need flow and lock hint */ - f = LuaStateGetFlow(luastate, &flow_lock); + f = LuaStateGetFlow(luastate); if (f == NULL) { lua_pushnil(luastate); lua_pushstring(luastate, "no flow"); @@ -301,24 +285,15 @@ static int LuaGetFlowint(lua_State *luastate) } /* lookup var */ - if (flow_lock == LUA_FLOW_NOT_LOCKED_BY_PARENT) - FLOWLOCK_RDLOCK(f); - fv = FlowVarGet(f, idx); if (fv == NULL) { SCLogDebug("fv NULL"); - if (flow_lock == LUA_FLOW_NOT_LOCKED_BY_PARENT) - FLOWLOCK_UNLOCK(f); - lua_pushnil(luastate); lua_pushstring(luastate, "no flow var"); return 2; } number = fv->data.fv_int.value; - if (flow_lock == LUA_FLOW_NOT_LOCKED_BY_PARENT) - FLOWLOCK_UNLOCK(f); - /* return value through luastate, as a luanumber */ lua_pushnumber(luastate, (lua_Number)number); SCLogDebug("retrieved flow:%p idx:%u value:%u", f, idx, number); @@ -334,7 +309,6 @@ int LuaSetFlowint(lua_State *luastate) Flow *f; DetectEngineThreadCtx *det_ctx; DetectLuaData *ld; - int flow_lock = 0; uint32_t number; lua_Number luanumber; @@ -361,7 +335,7 @@ int LuaSetFlowint(lua_State *luastate) } /* need flow and lock hint */ - f = LuaStateGetFlow(luastate, &flow_lock); + f = LuaStateGetFlow(luastate); if (f == NULL) { lua_pushnil(luastate); lua_pushstring(luastate, "no flow"); @@ -401,10 +375,7 @@ int LuaSetFlowint(lua_State *luastate) return 2; } - if (flow_lock == LUA_FLOW_NOT_LOCKED_BY_PARENT) - FlowVarAddInt(f, idx, number); - else - FlowVarAddIntNoLock(f, idx, number); + FlowVarAddInt(f, idx, number); SCLogDebug("stored flow:%p idx:%u value:%u", f, idx, number); return 0; @@ -417,7 +388,6 @@ static int LuaIncrFlowint(lua_State *luastate) Flow *f; FlowVar *fv; DetectLuaData *ld; - int flow_lock = 0; uint32_t number; /* need luajit data for id -> idx conversion */ @@ -432,7 +402,7 @@ static int LuaIncrFlowint(lua_State *luastate) } /* need flow and lock hint */ - f = LuaStateGetFlow(luastate, &flow_lock); + f = LuaStateGetFlow(luastate); if (f == NULL) { lua_pushnil(luastate); lua_pushstring(luastate, "no flow"); @@ -462,9 +432,6 @@ static int LuaIncrFlowint(lua_State *luastate) } /* lookup var */ - if (flow_lock == LUA_FLOW_NOT_LOCKED_BY_PARENT) - FLOWLOCK_RDLOCK(f); - fv = FlowVarGet(f, idx); if (fv == NULL) { number = 1; @@ -475,9 +442,6 @@ static int LuaIncrFlowint(lua_State *luastate) } FlowVarAddIntNoLock(f, idx, number); - if (flow_lock == LUA_FLOW_NOT_LOCKED_BY_PARENT) - FLOWLOCK_UNLOCK(f); - /* return value through luastate, as a luanumber */ lua_pushnumber(luastate, (lua_Number)number); SCLogDebug("incremented flow:%p idx:%u value:%u", f, idx, number); @@ -493,7 +457,6 @@ static int LuaDecrFlowint(lua_State *luastate) Flow *f; FlowVar *fv; DetectLuaData *ld; - int flow_lock = 0; uint32_t number; /* need luajit data for id -> idx conversion */ @@ -508,7 +471,7 @@ static int LuaDecrFlowint(lua_State *luastate) } /* need flow and lock hint */ - f = LuaStateGetFlow(luastate, &flow_lock); + f = LuaStateGetFlow(luastate); if (f == NULL) { lua_pushnil(luastate); lua_pushstring(luastate, "no flow"); @@ -538,9 +501,6 @@ static int LuaDecrFlowint(lua_State *luastate) } /* lookup var */ - if (flow_lock == LUA_FLOW_NOT_LOCKED_BY_PARENT) - FLOWLOCK_RDLOCK(f); - fv = FlowVarGet(f, idx); if (fv == NULL) { number = 0; @@ -551,9 +511,6 @@ static int LuaDecrFlowint(lua_State *luastate) } FlowVarAddIntNoLock(f, idx, number); - if (flow_lock == LUA_FLOW_NOT_LOCKED_BY_PARENT) - FLOWLOCK_UNLOCK(f); - /* return value through luastate, as a luanumber */ lua_pushnumber(luastate, (lua_Number)number); SCLogDebug("decremented flow:%p idx:%u value:%u", f, idx, number); @@ -563,7 +520,7 @@ static int LuaDecrFlowint(lua_State *luastate) } void LuaExtensionsMatchSetup(lua_State *lua_state, DetectLuaData *ld, DetectEngineThreadCtx *det_ctx, - Flow *f, int flow_locked, Packet *p, uint8_t flags) + Flow *f, Packet *p, uint8_t flags) { SCLogDebug("det_ctx %p, f %p", det_ctx, f); @@ -577,9 +534,9 @@ void LuaExtensionsMatchSetup(lua_State *lua_state, DetectLuaData *ld, DetectEngi lua_pushlightuserdata(lua_state, (void *)det_ctx); lua_settable(lua_state, LUA_REGISTRYINDEX); - LuaStateSetFlow(lua_state, f, flow_locked); + LuaStateSetFlow(lua_state, f); - if (det_ctx->tx_id_set && flow_locked == LUA_FLOW_LOCKED_BY_PARENT) { + if (det_ctx->tx_id_set) { if (f && f->alstate) { void *txptr = AppLayerParserGetTx(f->proto, f->alproto, f->alstate, det_ctx->tx_id); if (txptr) { diff --git a/src/detect-lua-extensions.h b/src/detect-lua-extensions.h index b8aa27366e..54a465783e 100644 --- a/src/detect-lua-extensions.h +++ b/src/detect-lua-extensions.h @@ -29,7 +29,7 @@ int LuaRegisterExtensions(lua_State *); void LuaExtensionsMatchSetup(lua_State *lua_state, DetectLuaData *, DetectEngineThreadCtx *det_ctx, - Flow *f, int flow_locked, Packet *p, uint8_t flags); + Flow *f, Packet *p, uint8_t flags); #endif /* HAVE_LUA */ #endif diff --git a/src/detect-lua.c b/src/detect-lua.c index 99cb13be37..3343a6be76 100644 --- a/src/detect-lua.c +++ b/src/detect-lua.c @@ -309,13 +309,8 @@ int DetectLuaMatchBuffer(DetectEngineThreadCtx *det_ctx, Signature *s, SigMatch if (tluajit == NULL) SCReturnInt(0); - /* setup extension data for use in lua c functions */ - int flow_lock = (f != NULL) ? /* if we have a flow, it's locked */ - LUA_FLOW_LOCKED_BY_PARENT : - LUA_FLOW_NOT_LOCKED_BY_PARENT; - LuaExtensionsMatchSetup(tluajit->luastate, luajit, det_ctx, - f, flow_lock, /* no packet in the ctx */NULL, 0); + f, /* no packet in the ctx */NULL, 0); /* prepare data to pass to script */ lua_getglobal(tluajit->luastate, "match"); @@ -424,12 +419,8 @@ static int DetectLuaMatch (ThreadVars *tv, DetectEngineThreadCtx *det_ctx, LuaStateSetThreadVars(tluajit->luastate, tv); - int flow_lock = (p->flow != NULL) ? /* if we have a flow, it's locked */ - LUA_FLOW_LOCKED_BY_PARENT : - LUA_FLOW_NOT_LOCKED_BY_PARENT; - LuaExtensionsMatchSetup(tluajit->luastate, luajit, det_ctx, - p->flow, flow_lock, p, flags); + p->flow, p, flags); if ((tluajit->flags & DATATYPE_PAYLOAD) && p->payload_len == 0) SCReturnInt(0); @@ -554,8 +545,7 @@ static int DetectLuaAppMatchCommon (ThreadVars *t, DetectEngineThreadCtx *det_ct /* setup extension data for use in lua c functions */ LuaExtensionsMatchSetup(tluajit->luastate, luajit, det_ctx, - f, /* flow is locked */LUA_FLOW_LOCKED_BY_PARENT, - NULL, flags); + f, NULL, flags); if (tluajit->alproto != ALPROTO_UNKNOWN) { int alproto = f->alproto; diff --git a/src/output-lua.c b/src/output-lua.c index 1bd1aae695..b71b0e3736 100644 --- a/src/output-lua.c +++ b/src/output-lua.c @@ -106,7 +106,7 @@ static int LuaTxLogger(ThreadVars *tv, void *thread_data, const Packet *p, Flow LuaStateSetThreadVars(td->lua_ctx->luastate, tv); LuaStateSetPacket(td->lua_ctx->luastate, (Packet *)p); LuaStateSetTX(td->lua_ctx->luastate, txptr); - LuaStateSetFlow(td->lua_ctx->luastate, f, /* locked */LUA_FLOW_LOCKED_BY_PARENT); + LuaStateSetFlow(td->lua_ctx->luastate, f); /* prepare data to pass to script */ lua_getglobal(td->lua_ctx->luastate, "log"); @@ -150,7 +150,7 @@ static int LuaStreamingLogger(ThreadVars *tv, void *thread_data, const Flow *f, LuaStateSetThreadVars(td->lua_ctx->luastate, tv); if (flags & OUTPUT_STREAMING_FLAG_TRANSACTION) LuaStateSetTX(td->lua_ctx->luastate, txptr); - LuaStateSetFlow(td->lua_ctx->luastate, (Flow *)f, /* locked */LUA_FLOW_LOCKED_BY_PARENT); + LuaStateSetFlow(td->lua_ctx->luastate, (Flow *)f); LuaStateSetStreamingBuffer(td->lua_ctx->luastate, &b); /* prepare data to pass to script */ @@ -213,7 +213,7 @@ static int LuaPacketLoggerAlerts(ThreadVars *tv, void *thread_data, const Packet LuaStateSetThreadVars(td->lua_ctx->luastate, tv); LuaStateSetPacket(td->lua_ctx->luastate, (Packet *)p); - LuaStateSetFlow(td->lua_ctx->luastate, p->flow, /* unlocked */LUA_FLOW_NOT_LOCKED_BY_PARENT); + LuaStateSetFlow(td->lua_ctx->luastate, p->flow); LuaStateSetPacketAlert(td->lua_ctx->luastate, (PacketAlert *)pa); /* prepare data to pass to script */ @@ -258,7 +258,7 @@ static int LuaPacketLoggerSsh(ThreadVars *tv, void *thread_data, const Packet *p LuaStateSetThreadVars(td->lua_ctx->luastate, tv); LuaStateSetPacket(td->lua_ctx->luastate, (Packet *)p); - LuaStateSetFlow(td->lua_ctx->luastate, p->flow, /* unlocked */LUA_FLOW_NOT_LOCKED_BY_PARENT); + LuaStateSetFlow(td->lua_ctx->luastate, p->flow); int retval = lua_pcall(td->lua_ctx->luastate, 0, 0, 0); if (retval != 0) { @@ -347,7 +347,7 @@ static int LuaPacketLogger(ThreadVars *tv, void *thread_data, const Packet *p) LuaStateSetThreadVars(td->lua_ctx->luastate, tv); LuaStateSetPacket(td->lua_ctx->luastate, (Packet *)p); - LuaStateSetFlow(td->lua_ctx->luastate, p->flow, /* unlocked */LUA_FLOW_NOT_LOCKED_BY_PARENT); + LuaStateSetFlow(td->lua_ctx->luastate, p->flow); /* prepare data to pass to script */ lua_newtable(td->lua_ctx->luastate); @@ -398,7 +398,7 @@ static int LuaFileLogger(ThreadVars *tv, void *thread_data, const Packet *p, con LuaStateSetThreadVars(td->lua_ctx->luastate, tv); LuaStateSetPacket(td->lua_ctx->luastate, (Packet *)p); LuaStateSetTX(td->lua_ctx->luastate, txptr); - LuaStateSetFlow(td->lua_ctx->luastate, p->flow, /* locked */LUA_FLOW_LOCKED_BY_PARENT); + LuaStateSetFlow(td->lua_ctx->luastate, p->flow); LuaStateSetFile(td->lua_ctx->luastate, (File *)ff); /* get the lua function to call */ @@ -429,7 +429,7 @@ static int LuaFlowLogger(ThreadVars *tv, void *thread_data, Flow *f) SCMutexLock(&td->lua_ctx->m); LuaStateSetThreadVars(td->lua_ctx->luastate, tv); - LuaStateSetFlow(td->lua_ctx->luastate, f, /* locked */LUA_FLOW_LOCKED_BY_PARENT); + LuaStateSetFlow(td->lua_ctx->luastate, f); /* get the lua function to call */ lua_getglobal(td->lua_ctx->luastate, "log"); diff --git a/src/util-lua-common.c b/src/util-lua-common.c index d44d5a7c82..367374d76c 100644 --- a/src/util-lua-common.c +++ b/src/util-lua-common.c @@ -210,18 +210,12 @@ static int LuaCallbackTimeStringPushToStackFromFlow(lua_State *luastate, const F static int LuaCallbackFlowTimeString(lua_State *luastate) { int r = 0; - int locked = 0; - Flow *flow = LuaStateGetFlow(luastate, &locked); + Flow *flow = LuaStateGetFlow(luastate); if (flow == NULL) return LuaCallbackError(luastate, "internal error: no flow"); - if (locked == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - FLOWLOCK_RDLOCK(flow); - r = LuaCallbackTimeStringPushToStackFromFlow(luastate, flow); - FLOWLOCK_UNLOCK(flow); - } else { - r = LuaCallbackTimeStringPushToStackFromFlow(luastate, flow); - } + r = LuaCallbackTimeStringPushToStackFromFlow(luastate, flow); + return r; } @@ -345,18 +339,12 @@ static int LuaCallbackTuplePushToStackFromFlow(lua_State *luastate, const Flow * static int LuaCallbackTupleFlow(lua_State *luastate) { int r = 0; - int lock_hint = 0; - Flow *f = LuaStateGetFlow(luastate, &lock_hint); + Flow *f = LuaStateGetFlow(luastate); if (f == NULL) return LuaCallbackError(luastate, "internal error: no flow"); - if (lock_hint == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - FLOWLOCK_RDLOCK(f); - r = LuaCallbackTuplePushToStackFromFlow(luastate, f); - FLOWLOCK_UNLOCK(f); - } else { - r = LuaCallbackTuplePushToStackFromFlow(luastate, f); - } + r = LuaCallbackTuplePushToStackFromFlow(luastate, f); + return r; } @@ -384,18 +372,12 @@ static int LuaCallbackAppLayerProtoPushToStackFromFlow(lua_State *luastate, cons static int LuaCallbackAppLayerProtoFlow(lua_State *luastate) { int r = 0; - int lock_hint = 0; - Flow *f = LuaStateGetFlow(luastate, &lock_hint); + Flow *f = LuaStateGetFlow(luastate); if (f == NULL) return LuaCallbackError(luastate, "internal error: no flow"); - if (lock_hint == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - FLOWLOCK_RDLOCK(f); - r = LuaCallbackAppLayerProtoPushToStackFromFlow(luastate, f); - FLOWLOCK_UNLOCK(f); - } else { - r = LuaCallbackAppLayerProtoPushToStackFromFlow(luastate, f); - } + r = LuaCallbackAppLayerProtoPushToStackFromFlow(luastate, f); + return r; } @@ -423,18 +405,12 @@ static int LuaCallbackStatsPushToStackFromFlow(lua_State *luastate, const Flow * static int LuaCallbackStatsFlow(lua_State *luastate) { int r = 0; - int lock_hint = 0; - Flow *f = LuaStateGetFlow(luastate, &lock_hint); + Flow *f = LuaStateGetFlow(luastate); if (f == NULL) return LuaCallbackError(luastate, "internal error: no flow"); - if (lock_hint == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - FLOWLOCK_RDLOCK(f); - r = LuaCallbackStatsPushToStackFromFlow(luastate, f); - FLOWLOCK_UNLOCK(f); - } else { - r = LuaCallbackStatsPushToStackFromFlow(luastate, f); - } + r = LuaCallbackStatsPushToStackFromFlow(luastate, f); + return r; } @@ -771,18 +747,11 @@ int LuaRegisterFunctions(lua_State *luastate) int LuaStateNeedProto(lua_State *luastate, AppProto alproto) { AppProto flow_alproto = 0; - int locked = 0; - Flow *flow = LuaStateGetFlow(luastate, &locked); + Flow *flow = LuaStateGetFlow(luastate); if (flow == NULL) return LuaCallbackError(luastate, "internal error: no flow"); - if (locked == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - FLOWLOCK_RDLOCK(flow); - flow_alproto = flow->alproto; - FLOWLOCK_UNLOCK(flow); - } else { - flow_alproto = flow->alproto; - } + flow_alproto = flow->alproto; return (alproto == flow_alproto); diff --git a/src/util-lua-smtp.c b/src/util-lua-smtp.c index a64c709832..8fca9131a1 100644 --- a/src/util-lua-smtp.c +++ b/src/util-lua-smtp.c @@ -105,8 +105,7 @@ static int SMTPGetMimeField(lua_State *luastate) if(!(LuaStateNeedProto(luastate, ALPROTO_SMTP))) { return LuaCallbackError(luastate, "error: protocol not SMTP"); } - int lock_hint = 0; - Flow *flow = LuaStateGetFlow(luastate, &lock_hint); + Flow *flow = LuaStateGetFlow(luastate); /* check that flow exist */ if(flow == NULL) { return LuaCallbackError(luastate, "Error: no flow found"); @@ -115,17 +114,8 @@ static int SMTPGetMimeField(lua_State *luastate) if (name == NULL) return LuaCallbackError(luastate, "1st argument missing, empty or wrong type"); - /* lock check */ - if(lock_hint == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - FLOWLOCK_RDLOCK(flow); - /* get specific MIME field */ - GetMimeDecField(luastate, flow, name); - /* unlock flow mutex to allow for multithreading */ - FLOWLOCK_UNLOCK(flow); - /* return number of fields pushed to luastate */ - } else { /* if mutex already locked */ - GetMimeDecField(luastate, flow, name); - } + GetMimeDecField(luastate, flow, name); + return 1; } @@ -195,22 +185,14 @@ static int SMTPGetMimeList(lua_State *luastate) if(!(LuaStateNeedProto(luastate, ALPROTO_SMTP))) { return LuaCallbackError(luastate, "Error: protocol not SMTP"); } - /* mutex lock indicator var */ - int lock_hint = 0; /* Extract network flow */ - Flow *flow = LuaStateGetFlow(luastate, &lock_hint); + Flow *flow = LuaStateGetFlow(luastate); if(flow == NULL) { return LuaCallbackError(luastate, "Error: no flow found"); } - /* check if flow already locked */ - if(lock_hint == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - /* mutexlock flow */ - FLOWLOCK_RDLOCK(flow); - GetMimeList(luastate, flow); - FLOWLOCK_UNLOCK(flow); - } else { - GetMimeList(luastate, flow); - } + + GetMimeList(luastate, flow); + return 1; } @@ -260,22 +242,14 @@ static int SMTPGetMailFrom(lua_State *luastate) if(!(LuaStateNeedProto(luastate, ALPROTO_SMTP))) { return LuaCallbackError(luastate, "Error: protocol not SMTP"); } - /* use lock_hint to check for mutexlock on flow */ - int lock_hint = 0; /* Extract flow, with lockhint to check mutexlocking */ - Flow *flow = LuaStateGetFlow(luastate, &lock_hint); + Flow *flow = LuaStateGetFlow(luastate); if(flow == NULL) { return LuaCallbackError(luastate, "Internal Error: no flow"); } - /* check if already mutexlocked by parents */ - if(lock_hint == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - /* mutexlock flow */ - FLOWLOCK_RDLOCK(flow); - GetMailFrom(luastate, flow); - FLOWLOCK_UNLOCK(flow); - } else { - GetMailFrom(luastate, flow); - } + + GetMailFrom(luastate, flow); + return 1; } @@ -335,23 +309,14 @@ static int SMTPGetRcptList(lua_State *luastate) if(!(LuaStateNeedProto(luastate, ALPROTO_SMTP))) { return LuaCallbackError(luastate, "Error: protocol not SMTP"); } - /* create lockhint var for flowlock check. */ - int lock_hint = 0; /* Extract flow, with lockhint to check mutexlocking */ - Flow *flow = LuaStateGetFlow(luastate, &lock_hint); + Flow *flow = LuaStateGetFlow(luastate); if(flow == NULL) { return LuaCallbackError(luastate, "Internal error: no flow"); } - /* check if already mutexlocked by parents */ - if(lock_hint == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - /* lock flow */ - FLOWLOCK_RDLOCK(flow); - GetRcptList(luastate, flow); - /* open flow */ - FLOWLOCK_UNLOCK(flow); - } else { - GetRcptList(luastate, flow); - } + + GetRcptList(luastate, flow); + /* return 1 since we allways push one table to luastate */ return 1; } diff --git a/src/util-lua-ssh.c b/src/util-lua-ssh.c index df232c8118..892190080f 100644 --- a/src/util-lua-ssh.c +++ b/src/util-lua-ssh.c @@ -79,18 +79,12 @@ static int SshGetServerProtoVersion(lua_State *luastate) if (!(LuaStateNeedProto(luastate, ALPROTO_SSH))) return LuaCallbackError(luastate, "error: protocol not ssh"); - int lock_hint = 0; - Flow *f = LuaStateGetFlow(luastate, &lock_hint); + Flow *f = LuaStateGetFlow(luastate); if (f == NULL) return LuaCallbackError(luastate, "internal error: no flow"); - if (lock_hint == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - FLOWLOCK_RDLOCK(f); - r = GetServerProtoVersion(luastate, f); - FLOWLOCK_UNLOCK(f); - } else { - r = GetServerProtoVersion(luastate, f); - } + r = GetServerProtoVersion(luastate, f); + return r; } @@ -116,18 +110,12 @@ static int SshGetServerSoftwareVersion(lua_State *luastate) if (!(LuaStateNeedProto(luastate, ALPROTO_SSH))) return LuaCallbackError(luastate, "error: protocol not ssh"); - int lock_hint = 0; - Flow *f = LuaStateGetFlow(luastate, &lock_hint); + Flow *f = LuaStateGetFlow(luastate); if (f == NULL) return LuaCallbackError(luastate, "internal error: no flow"); - if (lock_hint == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - FLOWLOCK_RDLOCK(f); - r = GetServerSoftwareVersion(luastate, f); - FLOWLOCK_UNLOCK(f); - } else { - r = GetServerSoftwareVersion(luastate, f); - } + r = GetServerSoftwareVersion(luastate, f); + return r; } @@ -153,18 +141,12 @@ static int SshGetClientProtoVersion(lua_State *luastate) if (!(LuaStateNeedProto(luastate, ALPROTO_SSH))) return LuaCallbackError(luastate, "error: protocol not ssh"); - int lock_hint = 0; - Flow *f = LuaStateGetFlow(luastate, &lock_hint); + Flow *f = LuaStateGetFlow(luastate); if (f == NULL) return LuaCallbackError(luastate, "internal error: no flow"); - if (lock_hint == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - FLOWLOCK_RDLOCK(f); - r = GetClientProtoVersion(luastate, f); - FLOWLOCK_UNLOCK(f); - } else { - r = GetClientProtoVersion(luastate, f); - } + r = GetClientProtoVersion(luastate, f); + return r; } @@ -190,18 +172,12 @@ static int SshGetClientSoftwareVersion(lua_State *luastate) if (!(LuaStateNeedProto(luastate, ALPROTO_SSH))) return LuaCallbackError(luastate, "error: protocol not ssh"); - int lock_hint = 0; - Flow *f = LuaStateGetFlow(luastate, &lock_hint); + Flow *f = LuaStateGetFlow(luastate); if (f == NULL) return LuaCallbackError(luastate, "internal error: no flow"); - if (lock_hint == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - FLOWLOCK_RDLOCK(f); - r = GetClientSoftwareVersion(luastate, f); - FLOWLOCK_UNLOCK(f); - } else { - r = GetClientSoftwareVersion(luastate, f); - } + r = GetClientSoftwareVersion(luastate, f); + return r; } diff --git a/src/util-lua-tls.c b/src/util-lua-tls.c index e17e512e41..5d0a7491eb 100644 --- a/src/util-lua-tls.c +++ b/src/util-lua-tls.c @@ -118,18 +118,12 @@ static int TlsGetCertInfo(lua_State *luastate) int direction = LuaStateGetDirection(luastate); - int lock_hint = 0; - Flow *f = LuaStateGetFlow(luastate, &lock_hint); + Flow *f = LuaStateGetFlow(luastate); if (f == NULL) return LuaCallbackError(luastate, "internal error: no flow"); - if (lock_hint == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - FLOWLOCK_RDLOCK(f); - r = GetCertInfo(luastate, f, direction); - FLOWLOCK_UNLOCK(f); - } else { - r = GetCertInfo(luastate, f, direction); - } + r = GetCertInfo(luastate, f, direction); + return r; } @@ -155,18 +149,12 @@ static int TlsGetSNI(lua_State *luastate) if (!(LuaStateNeedProto(luastate, ALPROTO_TLS))) return LuaCallbackError(luastate, "error: protocol not tls"); - int lock_hint = 0; - Flow *f = LuaStateGetFlow(luastate, &lock_hint); + Flow *f = LuaStateGetFlow(luastate); if (f == NULL) return LuaCallbackError(luastate, "internal error: no flow"); - if (lock_hint == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - FLOWLOCK_RDLOCK(f); - r = GetSNI(luastate, f); - FLOWLOCK_UNLOCK(f); - } else { - r = GetSNI(luastate, f); - } + r = GetSNI(luastate, f); + return r; } @@ -217,18 +205,12 @@ static int TlsGetCertChain(lua_State *luastate) int direction = LuaStateGetDirection(luastate); - int lock_hint = 0; - Flow *f = LuaStateGetFlow(luastate, &lock_hint); + Flow *f = LuaStateGetFlow(luastate); if (f == NULL) return LuaCallbackError(luastate, "internal error: no flow"); - if (lock_hint == LUA_FLOW_NOT_LOCKED_BY_PARENT) { - FLOWLOCK_RDLOCK(f); - r = GetCertChain(luastate, f, direction); - FLOWLOCK_UNLOCK(f); - } else { - r = GetCertChain(luastate, f, direction); - } + r = GetCertChain(luastate, f, direction); + return r; } diff --git a/src/util-lua.c b/src/util-lua.c index 32d206c35b..54524826bd 100644 --- a/src/util-lua.c +++ b/src/util-lua.c @@ -124,10 +124,9 @@ void LuaStateSetTX(lua_State *luastate, void *txptr) lua_settable(luastate, LUA_REGISTRYINDEX); } -Flow *LuaStateGetFlow(lua_State *luastate, int *lock_hint) +Flow *LuaStateGetFlow(lua_State *luastate) { Flow *f = NULL; - int need_flow_lock = 0; lua_pushlightuserdata(luastate, (void *)&lua_ext_key_flow); lua_gettable(luastate, LUA_REGISTRYINDEX); @@ -136,13 +135,11 @@ Flow *LuaStateGetFlow(lua_State *luastate, int *lock_hint) /* need flow lock hint */ lua_pushlightuserdata(luastate, (void *)&lua_ext_key_flow_lock_hint); lua_gettable(luastate, LUA_REGISTRYINDEX); - need_flow_lock = lua_toboolean(luastate, -1); - *lock_hint = need_flow_lock; return f; } -void LuaStateSetFlow(lua_State *luastate, Flow *f, int need_flow_lock) +void LuaStateSetFlow(lua_State *luastate, Flow *f) { /* flow */ lua_pushlightuserdata(luastate, (void *)&lua_ext_key_flow); @@ -151,7 +148,8 @@ void LuaStateSetFlow(lua_State *luastate, Flow *f, int need_flow_lock) /* flow lock status hint */ lua_pushlightuserdata(luastate, (void *)&lua_ext_key_flow_lock_hint); - lua_pushboolean(luastate, need_flow_lock); + /* locking is not required, set to 0 for backwards compatibility */ + lua_pushboolean(luastate, 0); lua_settable(luastate, LUA_REGISTRYINDEX); } diff --git a/src/util-lua.h b/src/util-lua.h index 4ea4c60513..492007a62a 100644 --- a/src/util-lua.h +++ b/src/util-lua.h @@ -32,9 +32,6 @@ typedef struct LuaStreamingBuffer_ { uint8_t flags; } LuaStreamingBuffer; -#define LUA_FLOW_LOCKED_BY_PARENT 0 -#define LUA_FLOW_NOT_LOCKED_BY_PARENT 1 - /* gets */ /** \brief get tv pointer from the lua state */ @@ -44,14 +41,10 @@ Packet *LuaStateGetPacket(lua_State *luastate); void *LuaStateGetTX(lua_State *luastate); /** \brief get flow pointer from lua state - * - * \param locked_by_parent[out] bool indicating if flow is locked - * (LUA_FLOW_LOCKED_BY_PARENT) or unlocked - * (LUA_FLOW_NOT_LOCKED_BY_PARENT) * * \retval f flow poiner or NULL if it was not set */ -Flow *LuaStateGetFlow(lua_State *luastate, int *locked_by_parent); +Flow *LuaStateGetFlow(lua_State *luastate); PacketAlert *LuaStateGetPacketAlert(lua_State *luastate); @@ -70,11 +63,8 @@ void LuaStateSetTX(lua_State *luastate, void *tx); /** \brief set a flow pointer in the lua state * * \param f flow pointer - * \param locked_by_parent bool indicating if flow is locked - * (LUA_FLOW_LOCKED_BY_PARENT) or unlocked - * (LUA_FLOW_NOT_LOCKED_BY_PARENT) */ -void LuaStateSetFlow(lua_State *luastate, Flow *f, int locked_by_parent); +void LuaStateSetFlow(lua_State *luastate, Flow *f); void LuaStateSetPacketAlert(lua_State *luastate, PacketAlert *pa);