From f2da5dbbad2d5d41b12291fcef0b41f3d54ec1d7 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 3 Mar 2014 14:11:00 +0100 Subject: [PATCH] detect-lua: convert extensions to use flow wrappers Use the new flow wrapper functions in the lua flowvar and flowint extensions. --- src/detect-luajit-extensions.c | 85 ++++++---------------------------- 1 file changed, 15 insertions(+), 70 deletions(-) diff --git a/src/detect-luajit-extensions.c b/src/detect-luajit-extensions.c index 1ea1497813..5fb9b0362c 100644 --- a/src/detect-luajit-extensions.c +++ b/src/detect-luajit-extensions.c @@ -60,10 +60,10 @@ #ifdef HAVE_LUA +#include "util-lua.h" + static const char luaext_key_ld[] = "suricata:luajitdata"; static const char luaext_key_det_ctx[] = "suricata:det_ctx"; -static const char luaext_key_flow[] = "suricata:flow"; -static const char luaext_key_need_flow_lock[] = "suricata:need_flow_lock"; static int LuajitGetFlowvar(lua_State *luastate) { @@ -85,22 +85,14 @@ static int LuajitGetFlowvar(lua_State *luastate) return 2; } - /* need flow */ - lua_pushlightuserdata(luastate, (void *)&luaext_key_flow); - lua_gettable(luastate, LUA_REGISTRYINDEX); - f = lua_touserdata(luastate, -1); - SCLogDebug("f %p", f); + /* need flow and lock hint */ + f = LuaStateGetFlow(luastate, &need_flow_lock); if (f == NULL) { lua_pushnil(luastate); lua_pushstring(luastate, "no flow"); return 2; } - /* need flow lock hint */ - lua_pushlightuserdata(luastate, (void *)&luaext_key_need_flow_lock); - lua_gettable(luastate, LUA_REGISTRYINDEX); - need_flow_lock = lua_toboolean(luastate, -1); - /* need flowvar idx */ if (!lua_isnumber(luastate, 1)) { lua_pushnil(luastate); @@ -192,22 +184,14 @@ int LuajitSetFlowvar(lua_State *luastate) return 2; } - /* need flow */ - lua_pushlightuserdata(luastate, (void *)&luaext_key_flow); - lua_gettable(luastate, LUA_REGISTRYINDEX); - f = lua_touserdata(luastate, -1); - SCLogDebug("f %p", f); + /* need flow and lock hint */ + f = LuaStateGetFlow(luastate, &need_flow_lock); if (f == NULL) { lua_pushnil(luastate); lua_pushstring(luastate, "no flow"); return 2; } - /* need flow lock hint */ - lua_pushlightuserdata(luastate, (void *)&luaext_key_need_flow_lock); - lua_gettable(luastate, LUA_REGISTRYINDEX); - need_flow_lock = lua_toboolean(luastate, -1); - /* need flowvar idx */ if (!lua_isnumber(luastate, 1)) { lua_pushnil(luastate); @@ -292,22 +276,14 @@ static int LuajitGetFlowint(lua_State *luastate) return 2; } - /* need flow */ - lua_pushlightuserdata(luastate, (void *)&luaext_key_flow); - lua_gettable(luastate, LUA_REGISTRYINDEX); - f = lua_touserdata(luastate, -1); - SCLogDebug("f %p", f); + /* need flow and lock hint */ + f = LuaStateGetFlow(luastate, &need_flow_lock); if (f == NULL) { lua_pushnil(luastate); lua_pushstring(luastate, "no flow"); return 2; } - /* need flow lock hint */ - lua_pushlightuserdata(luastate, (void *)&luaext_key_need_flow_lock); - lua_gettable(luastate, LUA_REGISTRYINDEX); - need_flow_lock = lua_toboolean(luastate, -1); - /* need flowint idx */ if (!lua_isnumber(luastate, 1)) { SCLogDebug("1st arg not a number"); @@ -390,20 +366,13 @@ int LuajitSetFlowint(lua_State *luastate) return 2; } - /* need flow */ - lua_pushlightuserdata(luastate, (void *)&luaext_key_flow); - lua_gettable(luastate, LUA_REGISTRYINDEX); - f = lua_touserdata(luastate, -1); - SCLogDebug("f %p", f); + /* need flow and lock hint */ + f = LuaStateGetFlow(luastate, &need_flow_lock); if (f == NULL) { lua_pushnil(luastate); lua_pushstring(luastate, "no flow"); return 2; } - /* need flow lock hint */ - lua_pushlightuserdata(luastate, (void *)&luaext_key_need_flow_lock); - lua_gettable(luastate, LUA_REGISTRYINDEX); - need_flow_lock = lua_toboolean(luastate, -1); /* need flowint idx */ if (!lua_isnumber(luastate, 1)) { @@ -468,22 +437,14 @@ static int LuajitIncrFlowint(lua_State *luastate) return 2; } - /* need flow */ - lua_pushlightuserdata(luastate, (void *)&luaext_key_flow); - lua_gettable(luastate, LUA_REGISTRYINDEX); - f = lua_touserdata(luastate, -1); - SCLogDebug("f %p", f); + /* need flow and lock hint */ + f = LuaStateGetFlow(luastate, &need_flow_lock); if (f == NULL) { lua_pushnil(luastate); lua_pushstring(luastate, "no flow"); return 2; } - /* need flow lock hint */ - lua_pushlightuserdata(luastate, (void *)&luaext_key_need_flow_lock); - lua_gettable(luastate, LUA_REGISTRYINDEX); - need_flow_lock = lua_toboolean(luastate, -1); - /* need flowint idx */ if (!lua_isnumber(luastate, 1)) { SCLogDebug("1st arg not a number"); @@ -552,22 +513,14 @@ static int LuajitDecrFlowint(lua_State *luastate) return 2; } - /* need flow */ - lua_pushlightuserdata(luastate, (void *)&luaext_key_flow); - lua_gettable(luastate, LUA_REGISTRYINDEX); - f = lua_touserdata(luastate, -1); - SCLogDebug("f %p", f); + /* need flow and lock hint */ + f = LuaStateGetFlow(luastate, &need_flow_lock); if (f == NULL) { lua_pushnil(luastate); lua_pushstring(luastate, "no flow"); return 2; } - /* need flow lock hint */ - lua_pushlightuserdata(luastate, (void *)&luaext_key_need_flow_lock); - lua_gettable(luastate, LUA_REGISTRYINDEX); - need_flow_lock = lua_toboolean(luastate, -1); - /* need flowint idx */ if (!lua_isnumber(luastate, 1)) { SCLogDebug("1st arg not a number"); @@ -629,15 +582,7 @@ void LuajitExtensionsMatchSetup(lua_State *lua_state, DetectLuajitData *ld, Dete lua_pushlightuserdata(lua_state, (void *)det_ctx); lua_settable(lua_state, LUA_REGISTRYINDEX); - /* flow */ - lua_pushlightuserdata(lua_state, (void *)&luaext_key_flow); - lua_pushlightuserdata(lua_state, (void *)f); - lua_settable(lua_state, LUA_REGISTRYINDEX); - - /* flow lock status hint */ - lua_pushlightuserdata(lua_state, (void *)&luaext_key_need_flow_lock); - lua_pushboolean(lua_state, need_flow_lock); - lua_settable(lua_state, LUA_REGISTRYINDEX); + LuaStateSetFlow(lua_state, f, need_flow_lock); } /**