Rename Lua code to just Lua

As we support regular Lua as well as LuaJIT, it makes more sense to call
it all Lua.
pull/1112/head
Victor Julien 11 years ago
parent adfe17280b
commit f23399d672

@ -156,8 +156,8 @@ detect-iprep.c detect-iprep.h \
detect-isdataat.c detect-isdataat.h \ detect-isdataat.c detect-isdataat.h \
detect-itype.c detect-itype.h \ detect-itype.c detect-itype.h \
detect-l3proto.c detect-l3proto.h \ detect-l3proto.c detect-l3proto.h \
detect-luajit.c detect-luajit.h \ detect-lua.c detect-lua.h \
detect-luajit-extensions.c detect-luajit-extensions.h \ detect-lua-extensions.c detect-lua-extensions.h \
detect-mark.c detect-mark.h \ detect-mark.c detect-mark.h \
detect-metadata.c detect-metadata.h \ detect-metadata.c detect-metadata.h \
detect-msg.c detect-msg.h \ detect-msg.c detect-msg.h \

@ -41,7 +41,7 @@
#include "detect-engine-content-inspection.h" #include "detect-engine-content-inspection.h"
#include "detect-uricontent.h" #include "detect-uricontent.h"
#include "detect-urilen.h" #include "detect-urilen.h"
#include "detect-luajit.h" #include "detect-lua.h"
#include "app-layer-dcerpc.h" #include "app-layer-dcerpc.h"
@ -535,14 +535,14 @@ int DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx
goto no_match; goto no_match;
#ifdef HAVE_LUA #ifdef HAVE_LUA
} }
else if (sm->type == DETECT_LUAJIT) { else if (sm->type == DETECT_LUA) {
SCLogDebug("lua starting"); SCLogDebug("lua starting");
/* for flowvar gets and sets we need to know the flow's lock status */ /* for flowvar gets and sets we need to know the flow's lock status */
int flow_lock = LUA_FLOW_LOCKED_BY_PARENT; int flow_lock = LUA_FLOW_LOCKED_BY_PARENT;
if (inspection_mode <= DETECT_ENGINE_CONTENT_INSPECTION_MODE_STREAM) if (inspection_mode <= DETECT_ENGINE_CONTENT_INSPECTION_MODE_STREAM)
flow_lock = LUA_FLOW_NOT_LOCKED_BY_PARENT; flow_lock = LUA_FLOW_NOT_LOCKED_BY_PARENT;
if (DetectLuajitMatchBuffer(det_ctx, s, sm, buffer, buffer_len, if (DetectLuaMatchBuffer(det_ctx, s, sm, buffer, buffer_len,
det_ctx->buffer_offset, f, flow_lock) != 1) det_ctx->buffer_offset, f, flow_lock) != 1)
{ {
SCLogDebug("lua no_match"); SCLogDebug("lua no_match");

@ -309,7 +309,7 @@ static void *DetectFilemagicThreadInit(void *data)
DetectFilemagicThreadData *t = SCMalloc(sizeof(DetectFilemagicThreadData)); DetectFilemagicThreadData *t = SCMalloc(sizeof(DetectFilemagicThreadData));
if (unlikely(t == NULL)) { if (unlikely(t == NULL)) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't alloc ctx memory"); SCLogError(SC_ERR_MEM_ALLOC, "couldn't alloc ctx memory");
return NULL; return NULL;
} }
memset(t, 0x00, sizeof(DetectFilemagicThreadData)); memset(t, 0x00, sizeof(DetectFilemagicThreadData));

@ -53,7 +53,7 @@
#include "stream-tcp.h" #include "stream-tcp.h"
#include "detect-luajit.h" #include "detect-lua.h"
#include "queue.h" #include "queue.h"
#include "util-cpu.h" #include "util-cpu.h"
@ -65,13 +65,13 @@
static const char luaext_key_ld[] = "suricata:luajitdata"; static const char luaext_key_ld[] = "suricata:luajitdata";
static const char luaext_key_det_ctx[] = "suricata:det_ctx"; static const char luaext_key_det_ctx[] = "suricata:det_ctx";
static int LuajitGetFlowvar(lua_State *luastate) static int LuaGetFlowvar(lua_State *luastate)
{ {
uint16_t idx; uint16_t idx;
int id; int id;
Flow *f; Flow *f;
FlowVar *fv; FlowVar *fv;
DetectLuajitData *ld; DetectLuaData *ld;
int flow_lock = 0; int flow_lock = 0;
/* need luajit data for id -> idx conversion */ /* need luajit data for id -> idx conversion */
@ -136,7 +136,7 @@ static int LuajitGetFlowvar(lua_State *luastate)
} }
int LuajitSetFlowvar(lua_State *luastate) int LuaSetFlowvar(lua_State *luastate)
{ {
uint16_t idx; uint16_t idx;
int id; int id;
@ -145,7 +145,7 @@ int LuajitSetFlowvar(lua_State *luastate)
int len; int len;
uint8_t *buffer; uint8_t *buffer;
DetectEngineThreadCtx *det_ctx; DetectEngineThreadCtx *det_ctx;
DetectLuajitData *ld; DetectLuaData *ld;
int flow_lock = 0; int flow_lock = 0;
/* need luajit data for id -> idx conversion */ /* need luajit data for id -> idx conversion */
@ -241,13 +241,13 @@ int LuajitSetFlowvar(lua_State *luastate)
return 0; return 0;
} }
static int LuajitGetFlowint(lua_State *luastate) static int LuaGetFlowint(lua_State *luastate)
{ {
uint16_t idx; uint16_t idx;
int id; int id;
Flow *f; Flow *f;
FlowVar *fv; FlowVar *fv;
DetectLuajitData *ld; DetectLuaData *ld;
int flow_lock = 0; int flow_lock = 0;
uint32_t number; uint32_t number;
@ -319,13 +319,13 @@ static int LuajitGetFlowint(lua_State *luastate)
} }
int LuajitSetFlowint(lua_State *luastate) int LuaSetFlowint(lua_State *luastate)
{ {
uint16_t idx; uint16_t idx;
int id; int id;
Flow *f; Flow *f;
DetectEngineThreadCtx *det_ctx; DetectEngineThreadCtx *det_ctx;
DetectLuajitData *ld; DetectLuaData *ld;
int flow_lock = 0; int flow_lock = 0;
uint32_t number; uint32_t number;
lua_Number luanumber; lua_Number luanumber;
@ -402,13 +402,13 @@ int LuajitSetFlowint(lua_State *luastate)
return 0; return 0;
} }
static int LuajitIncrFlowint(lua_State *luastate) static int LuaIncrFlowint(lua_State *luastate)
{ {
uint16_t idx; uint16_t idx;
int id; int id;
Flow *f; Flow *f;
FlowVar *fv; FlowVar *fv;
DetectLuajitData *ld; DetectLuaData *ld;
int flow_lock = 0; int flow_lock = 0;
uint32_t number; uint32_t number;
@ -478,13 +478,13 @@ static int LuajitIncrFlowint(lua_State *luastate)
} }
static int LuajitDecrFlowint(lua_State *luastate) static int LuaDecrFlowint(lua_State *luastate)
{ {
uint16_t idx; uint16_t idx;
int id; int id;
Flow *f; Flow *f;
FlowVar *fv; FlowVar *fv;
DetectLuajitData *ld; DetectLuaData *ld;
int flow_lock = 0; int flow_lock = 0;
uint32_t number; uint32_t number;
@ -554,7 +554,7 @@ static int LuajitDecrFlowint(lua_State *luastate)
} }
void LuajitExtensionsMatchSetup(lua_State *lua_state, DetectLuajitData *ld, DetectEngineThreadCtx *det_ctx, Flow *f, int flow_locked) void LuaExtensionsMatchSetup(lua_State *lua_state, DetectLuaData *ld, DetectEngineThreadCtx *det_ctx, Flow *f, int flow_locked)
{ {
SCLogDebug("det_ctx %p, f %p", det_ctx, f); SCLogDebug("det_ctx %p, f %p", det_ctx, f);
@ -574,24 +574,24 @@ void LuajitExtensionsMatchSetup(lua_State *lua_state, DetectLuajitData *ld, Dete
/** /**
* \brief Register Suricata Lua functions * \brief Register Suricata Lua functions
*/ */
int LuajitRegisterExtensions(lua_State *lua_state) int LuaRegisterExtensions(lua_State *lua_state)
{ {
lua_pushcfunction(lua_state, LuajitGetFlowvar); lua_pushcfunction(lua_state, LuaGetFlowvar);
lua_setglobal(lua_state, "ScFlowvarGet"); lua_setglobal(lua_state, "ScFlowvarGet");
lua_pushcfunction(lua_state, LuajitSetFlowvar); lua_pushcfunction(lua_state, LuaSetFlowvar);
lua_setglobal(lua_state, "ScFlowvarSet"); lua_setglobal(lua_state, "ScFlowvarSet");
lua_pushcfunction(lua_state, LuajitGetFlowint); lua_pushcfunction(lua_state, LuaGetFlowint);
lua_setglobal(lua_state, "ScFlowintGet"); lua_setglobal(lua_state, "ScFlowintGet");
lua_pushcfunction(lua_state, LuajitSetFlowint); lua_pushcfunction(lua_state, LuaSetFlowint);
lua_setglobal(lua_state, "ScFlowintSet"); lua_setglobal(lua_state, "ScFlowintSet");
lua_pushcfunction(lua_state, LuajitIncrFlowint); lua_pushcfunction(lua_state, LuaIncrFlowint);
lua_setglobal(lua_state, "ScFlowintIncr"); lua_setglobal(lua_state, "ScFlowintIncr");
lua_pushcfunction(lua_state, LuajitDecrFlowint); lua_pushcfunction(lua_state, LuaDecrFlowint);
lua_setglobal(lua_state, "ScFlowintDecr"); lua_setglobal(lua_state, "ScFlowintDecr");
return 0; return 0;

@ -21,14 +21,14 @@
* \author Victor Julien <victor@inliniac.net> * \author Victor Julien <victor@inliniac.net>
*/ */
#ifndef __DETECT_LUAJIT_EXT_H__ #ifndef __DETECT_LUA_EXT_H__
#define __DETECT_LUAJIT_EXT_H__ #define __DETECT_LUA_EXT_H__
#ifdef HAVE_LUA #ifdef HAVE_LUA
int LuajitRegisterExtensions(lua_State *); int LuaRegisterExtensions(lua_State *);
void LuajitExtensionsMatchSetup(lua_State *lua_state, void LuaExtensionsMatchSetup(lua_State *lua_state,
DetectLuajitData *, DetectEngineThreadCtx *det_ctx, DetectLuaData *, DetectEngineThreadCtx *det_ctx,
Flow *f, int flow_locked); Flow *f, int flow_locked);
#endif /* HAVE_LUA */ #endif /* HAVE_LUA */

@ -52,8 +52,8 @@
#include "stream-tcp.h" #include "stream-tcp.h"
#include "detect-luajit.h" #include "detect-lua.h"
#include "detect-luajit-extensions.h" #include "detect-lua-extensions.h"
#include "queue.h" #include "queue.h"
#include "util-cpu.h" #include "util-cpu.h"
@ -61,25 +61,25 @@
#ifndef HAVE_LUA #ifndef HAVE_LUA
static int DetectLuajitSetupNoSupport (DetectEngineCtx *a, Signature *b, char *c) static int DetectLuaSetupNoSupport (DetectEngineCtx *a, Signature *b, char *c)
{ {
SCLogError(SC_ERR_NO_LUAJIT_SUPPORT, "no LuaJIT support built in, needed for luajit keyword"); SCLogError(SC_ERR_NO_LUA_SUPPORT, "no Lua support built in, needed for lua/luajit keyword");
return -1; return -1;
} }
/** /**
* \brief Registration function for keyword: luajit * \brief Registration function for keyword: luajit
*/ */
void DetectLuajitRegister(void) void DetectLuaRegister(void)
{ {
sigmatch_table[DETECT_LUAJIT].name = "luajit"; sigmatch_table[DETECT_LUA].name = "lua";
sigmatch_table[DETECT_LUAJIT].alias = "lua"; sigmatch_table[DETECT_LUA].alias = "luajit";
sigmatch_table[DETECT_LUAJIT].Setup = DetectLuajitSetupNoSupport; sigmatch_table[DETECT_LUA].Setup = DetectLuaSetupNoSupport;
sigmatch_table[DETECT_LUAJIT].Free = NULL; sigmatch_table[DETECT_LUA].Free = NULL;
sigmatch_table[DETECT_LUAJIT].RegisterTests = NULL; sigmatch_table[DETECT_LUA].RegisterTests = NULL;
sigmatch_table[DETECT_LUAJIT].flags = SIGMATCH_NOT_BUILT; sigmatch_table[DETECT_LUA].flags = SIGMATCH_NOT_BUILT;
SCLogDebug("registering luajit rule option"); SCLogDebug("registering lua rule option");
return; return;
} }
@ -90,7 +90,7 @@ void DetectLuajitRegister(void)
/** \brief lua_State pool /** \brief lua_State pool
* *
* Luajit requires states to be alloc'd in memory <2GB. For this reason we * Lua requires states to be alloc'd in memory <2GB. For this reason we
* prealloc the states early during engine startup so we have a better chance * prealloc the states early during engine startup so we have a better chance
* of getting the states. We protect the pool with a lock as the detect * of getting the states. We protect the pool with a lock as the detect
* threads access it during their init and cleanup. * threads access it during their init and cleanup.
@ -107,25 +107,25 @@ static pthread_mutex_t luajit_states_lock = SCMUTEX_INITIALIZER;
#include "util-lua.h" #include "util-lua.h"
static int DetectLuajitMatch (ThreadVars *, DetectEngineThreadCtx *, static int DetectLuaMatch (ThreadVars *, DetectEngineThreadCtx *,
Packet *, Signature *, SigMatch *); Packet *, Signature *, SigMatch *);
static int DetectLuajitSetup (DetectEngineCtx *, Signature *, char *); static int DetectLuaSetup (DetectEngineCtx *, Signature *, char *);
static void DetectLuajitRegisterTests(void); static void DetectLuaRegisterTests(void);
static void DetectLuajitFree(void *); static void DetectLuaFree(void *);
/** /**
* \brief Registration function for keyword: luajit * \brief Registration function for keyword: luajit
*/ */
void DetectLuajitRegister(void) void DetectLuaRegister(void)
{ {
sigmatch_table[DETECT_LUAJIT].name = "luajit"; sigmatch_table[DETECT_LUA].name = "lua";
sigmatch_table[DETECT_LUAJIT].alias = "lua"; sigmatch_table[DETECT_LUA].alias = "luajit";
sigmatch_table[DETECT_LUAJIT].desc = "match via a luajit script"; sigmatch_table[DETECT_LUA].desc = "match via a luajit script";
sigmatch_table[DETECT_LUAJIT].url = "https://redmine.openinfosecfoundation.org/projects/suricata/wiki/Lua_scripting"; sigmatch_table[DETECT_LUA].url = "https://redmine.openinfosecfoundation.org/projects/suricata/wiki/Lua_scripting";
sigmatch_table[DETECT_LUAJIT].Match = DetectLuajitMatch; sigmatch_table[DETECT_LUA].Match = DetectLuaMatch;
sigmatch_table[DETECT_LUAJIT].Setup = DetectLuajitSetup; sigmatch_table[DETECT_LUA].Setup = DetectLuaSetup;
sigmatch_table[DETECT_LUAJIT].Free = DetectLuajitFree; sigmatch_table[DETECT_LUA].Free = DetectLuaFree;
sigmatch_table[DETECT_LUAJIT].RegisterTests = DetectLuajitRegisterTests; sigmatch_table[DETECT_LUA].RegisterTests = DetectLuaRegisterTests;
SCLogDebug("registering luajit rule option"); SCLogDebug("registering luajit rule option");
return; return;
@ -196,7 +196,7 @@ int DetectLuajitSetupStatesPool(int num, int reloads)
luajit_states = PoolInit(0, cnt, 0, LuaStatePoolAlloc, NULL, NULL, NULL, LuaStatePoolFree); luajit_states = PoolInit(0, cnt, 0, LuaStatePoolAlloc, NULL, NULL, NULL, LuaStatePoolFree);
if (luajit_states == NULL) { if (luajit_states == NULL) {
SCLogError(SC_ERR_LUAJIT_ERROR, "luastate pool init failed, luajit keywords won't work"); SCLogError(SC_ERR_LUA_ERROR, "luastate pool init failed, lua/luajit keywords won't work");
retval = -1; retval = -1;
} }
} }
@ -206,7 +206,7 @@ int DetectLuajitSetupStatesPool(int num, int reloads)
} }
#endif /* HAVE_LUAJIT */ #endif /* HAVE_LUAJIT */
static lua_State *DetectLuajitGetState(void) static lua_State *DetectLuaGetState(void)
{ {
lua_State *s = NULL; lua_State *s = NULL;
@ -221,7 +221,7 @@ static lua_State *DetectLuajitGetState(void)
return s; return s;
} }
static void DetectLuajitReturnState(lua_State *s) static void DetectLuaReturnState(lua_State *s)
{ {
if (s != NULL) { if (s != NULL) {
#ifdef HAVE_LUAJIT #ifdef HAVE_LUAJIT
@ -269,7 +269,7 @@ void LuaDumpStack(lua_State *state)
} }
} }
int DetectLuajitMatchBuffer(DetectEngineThreadCtx *det_ctx, Signature *s, SigMatch *sm, int DetectLuaMatchBuffer(DetectEngineThreadCtx *det_ctx, Signature *s, SigMatch *sm,
uint8_t *buffer, uint32_t buffer_len, uint32_t offset, uint8_t *buffer, uint32_t buffer_len, uint32_t offset,
Flow *f, int flow_lock) Flow *f, int flow_lock)
{ {
@ -279,16 +279,16 @@ int DetectLuajitMatchBuffer(DetectEngineThreadCtx *det_ctx, Signature *s, SigMat
if (buffer == NULL || buffer_len == 0) if (buffer == NULL || buffer_len == 0)
SCReturnInt(0); SCReturnInt(0);
DetectLuajitData *luajit = (DetectLuajitData *)sm->ctx; DetectLuaData *luajit = (DetectLuaData *)sm->ctx;
if (luajit == NULL) if (luajit == NULL)
SCReturnInt(0); SCReturnInt(0);
DetectLuajitThreadData *tluajit = (DetectLuajitThreadData *)DetectThreadCtxGetKeywordThreadCtx(det_ctx, luajit->thread_ctx_id); DetectLuaThreadData *tluajit = (DetectLuaThreadData *)DetectThreadCtxGetKeywordThreadCtx(det_ctx, luajit->thread_ctx_id);
if (tluajit == NULL) if (tluajit == NULL)
SCReturnInt(0); SCReturnInt(0);
/* setup extension data for use in lua c functions */ /* setup extension data for use in lua c functions */
LuajitExtensionsMatchSetup(tluajit->luastate, luajit, det_ctx, f, flow_lock); LuaExtensionsMatchSetup(tluajit->luastate, luajit, det_ctx, f, flow_lock);
/* prepare data to pass to script */ /* prepare data to pass to script */
lua_getglobal(tluajit->luastate, "match"); lua_getglobal(tluajit->luastate, "match");
@ -370,26 +370,26 @@ int DetectLuajitMatchBuffer(DetectEngineThreadCtx *det_ctx, Signature *s, SigMat
* \param det_ctx pattern matcher thread local data * \param det_ctx pattern matcher thread local data
* \param p packet * \param p packet
* \param s signature being inspected * \param s signature being inspected
* \param m sigmatch that we will cast into DetectLuajitData * \param m sigmatch that we will cast into DetectLuaData
* *
* \retval 0 no match * \retval 0 no match
* \retval 1 match * \retval 1 match
*/ */
static int DetectLuajitMatch (ThreadVars *tv, DetectEngineThreadCtx *det_ctx, static int DetectLuaMatch (ThreadVars *tv, DetectEngineThreadCtx *det_ctx,
Packet *p, Signature *s, SigMatch *m) Packet *p, Signature *s, SigMatch *m)
{ {
SCEnter(); SCEnter();
int ret = 0; int ret = 0;
DetectLuajitData *luajit = (DetectLuajitData *)m->ctx; DetectLuaData *luajit = (DetectLuaData *)m->ctx;
if (luajit == NULL) if (luajit == NULL)
SCReturnInt(0); SCReturnInt(0);
DetectLuajitThreadData *tluajit = (DetectLuajitThreadData *)DetectThreadCtxGetKeywordThreadCtx(det_ctx, luajit->thread_ctx_id); DetectLuaThreadData *tluajit = (DetectLuaThreadData *)DetectThreadCtxGetKeywordThreadCtx(det_ctx, luajit->thread_ctx_id);
if (tluajit == NULL) if (tluajit == NULL)
SCReturnInt(0); SCReturnInt(0);
/* setup extension data for use in lua c functions */ /* setup extension data for use in lua c functions */
LuajitExtensionsMatchSetup(tluajit->luastate, luajit, det_ctx, p->flow, /* flow not locked */LUA_FLOW_NOT_LOCKED_BY_PARENT); LuaExtensionsMatchSetup(tluajit->luastate, luajit, det_ctx, p->flow, /* flow not locked */LUA_FLOW_NOT_LOCKED_BY_PARENT);
if ((tluajit->flags & DATATYPE_PAYLOAD) && p->payload_len == 0) if ((tluajit->flags & DATATYPE_PAYLOAD) && p->payload_len == 0)
SCReturnInt(0); SCReturnInt(0);
@ -509,31 +509,31 @@ static int DetectLuajitMatch (ThreadVars *tv, DetectEngineThreadCtx *det_ctx,
static const char *ut_script = NULL; static const char *ut_script = NULL;
#endif #endif
static void *DetectLuajitThreadInit(void *data) static void *DetectLuaThreadInit(void *data)
{ {
int status; int status;
DetectLuajitData *luajit = (DetectLuajitData *)data; DetectLuaData *luajit = (DetectLuaData *)data;
BUG_ON(luajit == NULL); BUG_ON(luajit == NULL);
DetectLuajitThreadData *t = SCMalloc(sizeof(DetectLuajitThreadData)); DetectLuaThreadData *t = SCMalloc(sizeof(DetectLuaThreadData));
if (unlikely(t == NULL)) { if (unlikely(t == NULL)) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't alloc ctx memory"); SCLogError(SC_ERR_LUA_ERROR, "couldn't alloc ctx memory");
return NULL; return NULL;
} }
memset(t, 0x00, sizeof(DetectLuajitThreadData)); memset(t, 0x00, sizeof(DetectLuaThreadData));
t->alproto = luajit->alproto; t->alproto = luajit->alproto;
t->flags = luajit->flags; t->flags = luajit->flags;
t->luastate = DetectLuajitGetState(); t->luastate = DetectLuaGetState();
if (t->luastate == NULL) { if (t->luastate == NULL) {
SCLogError(SC_ERR_LUAJIT_ERROR, "luastate pool depleted"); SCLogError(SC_ERR_LUA_ERROR, "luastate pool depleted");
goto error; goto error;
} }
luaL_openlibs(t->luastate); luaL_openlibs(t->luastate);
LuajitRegisterExtensions(t->luastate); LuaRegisterExtensions(t->luastate);
lua_pushinteger(t->luastate, (lua_Integer)(luajit->sid)); lua_pushinteger(t->luastate, (lua_Integer)(luajit->sid));
lua_setglobal(t->luastate, "SCRuleSid"); lua_setglobal(t->luastate, "SCRuleSid");
@ -547,14 +547,14 @@ static void *DetectLuajitThreadInit(void *data)
if (ut_script != NULL) { if (ut_script != NULL) {
status = luaL_loadbuffer(t->luastate, ut_script, strlen(ut_script), "unittest"); status = luaL_loadbuffer(t->luastate, ut_script, strlen(ut_script), "unittest");
if (status) { if (status) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't load file: %s", lua_tostring(t->luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't load file: %s", lua_tostring(t->luastate, -1));
goto error; goto error;
} }
} else { } else {
#endif #endif
status = luaL_loadfile(t->luastate, luajit->filename); status = luaL_loadfile(t->luastate, luajit->filename);
if (status) { if (status) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't load file: %s", lua_tostring(t->luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't load file: %s", lua_tostring(t->luastate, -1));
goto error; goto error;
} }
#ifdef UNITTESTS #ifdef UNITTESTS
@ -563,7 +563,7 @@ static void *DetectLuajitThreadInit(void *data)
/* prime the script (or something) */ /* prime the script (or something) */
if (lua_pcall(t->luastate, 0, 0, 0) != 0) { if (lua_pcall(t->luastate, 0, 0, 0) != 0) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't prime file: %s", lua_tostring(t->luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't prime file: %s", lua_tostring(t->luastate, -1));
goto error; goto error;
} }
@ -571,17 +571,17 @@ static void *DetectLuajitThreadInit(void *data)
error: error:
if (t->luastate != NULL) if (t->luastate != NULL)
DetectLuajitReturnState(t->luastate); DetectLuaReturnState(t->luastate);
SCFree(t); SCFree(t);
return NULL; return NULL;
} }
static void DetectLuajitThreadFree(void *ctx) static void DetectLuaThreadFree(void *ctx)
{ {
if (ctx != NULL) { if (ctx != NULL) {
DetectLuajitThreadData *t = (DetectLuajitThreadData *)ctx; DetectLuaThreadData *t = (DetectLuaThreadData *)ctx;
if (t->luastate != NULL) if (t->luastate != NULL)
DetectLuajitReturnState(t->luastate); DetectLuaReturnState(t->luastate);
SCFree(t); SCFree(t);
} }
} }
@ -591,19 +591,19 @@ static void DetectLuajitThreadFree(void *ctx)
* *
* \param str Pointer to the user provided option * \param str Pointer to the user provided option
* *
* \retval luajit pointer to DetectLuajitData on success * \retval luajit pointer to DetectLuaData on success
* \retval NULL on failure * \retval NULL on failure
*/ */
static DetectLuajitData *DetectLuajitParse (char *str) static DetectLuaData *DetectLuaParse (char *str)
{ {
DetectLuajitData *luajit = NULL; DetectLuaData *luajit = NULL;
/* We have a correct luajit option */ /* We have a correct luajit option */
luajit = SCMalloc(sizeof(DetectLuajitData)); luajit = SCMalloc(sizeof(DetectLuaData));
if (unlikely(luajit == NULL)) if (unlikely(luajit == NULL))
goto error; goto error;
memset(luajit, 0x00, sizeof(DetectLuajitData)); memset(luajit, 0x00, sizeof(DetectLuaData));
if (strlen(str) && str[0] == '!') { if (strlen(str) && str[0] == '!') {
luajit->negated = 1; luajit->negated = 1;
@ -620,11 +620,11 @@ static DetectLuajitData *DetectLuajitParse (char *str)
error: error:
if (luajit != NULL) if (luajit != NULL)
DetectLuajitFree(luajit); DetectLuaFree(luajit);
return NULL; return NULL;
} }
static int DetectLuaSetupPrime(DetectEngineCtx *de_ctx, DetectLuajitData *ld) static int DetectLuaSetupPrime(DetectEngineCtx *de_ctx, DetectLuaData *ld)
{ {
int status; int status;
@ -638,14 +638,14 @@ static int DetectLuaSetupPrime(DetectEngineCtx *de_ctx, DetectLuajitData *ld)
if (ut_script != NULL) { if (ut_script != NULL) {
status = luaL_loadbuffer(luastate, ut_script, strlen(ut_script), "unittest"); status = luaL_loadbuffer(luastate, ut_script, strlen(ut_script), "unittest");
if (status) { if (status) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't load file: %s", lua_tostring(luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't load file: %s", lua_tostring(luastate, -1));
goto error; goto error;
} }
} else { } else {
#endif #endif
status = luaL_loadfile(luastate, ld->filename); status = luaL_loadfile(luastate, ld->filename);
if (status) { if (status) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't load file: %s", lua_tostring(luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't load file: %s", lua_tostring(luastate, -1));
goto error; goto error;
} }
#ifdef UNITTESTS #ifdef UNITTESTS
@ -654,19 +654,19 @@ static int DetectLuaSetupPrime(DetectEngineCtx *de_ctx, DetectLuajitData *ld)
/* prime the script (or something) */ /* prime the script (or something) */
if (lua_pcall(luastate, 0, 0, 0) != 0) { if (lua_pcall(luastate, 0, 0, 0) != 0) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't prime file: %s", lua_tostring(luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't prime file: %s", lua_tostring(luastate, -1));
goto error; goto error;
} }
lua_getglobal(luastate, "init"); lua_getglobal(luastate, "init");
if (lua_type(luastate, -1) != LUA_TFUNCTION) { if (lua_type(luastate, -1) != LUA_TFUNCTION) {
SCLogError(SC_ERR_LUAJIT_ERROR, "no init function in script"); SCLogError(SC_ERR_LUA_ERROR, "no init function in script");
goto error; goto error;
} }
lua_newtable(luastate); /* stack at -1 */ lua_newtable(luastate); /* stack at -1 */
if (lua_gettop(luastate) == 0 || lua_type(luastate, 2) != LUA_TTABLE) { if (lua_gettop(luastate) == 0 || lua_type(luastate, 2) != LUA_TTABLE) {
SCLogError(SC_ERR_LUAJIT_ERROR, "no table setup"); SCLogError(SC_ERR_LUA_ERROR, "no table setup");
goto error; goto error;
} }
@ -675,17 +675,17 @@ static int DetectLuaSetupPrime(DetectEngineCtx *de_ctx, DetectLuajitData *ld)
lua_settable(luastate, -3); lua_settable(luastate, -3);
if (lua_pcall(luastate, 1, 1, 0) != 0) { if (lua_pcall(luastate, 1, 1, 0) != 0) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't run script 'init' function: %s", lua_tostring(luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't run script 'init' function: %s", lua_tostring(luastate, -1));
goto error; goto error;
} }
/* process returns from script */ /* process returns from script */
if (lua_gettop(luastate) == 0) { if (lua_gettop(luastate) == 0) {
SCLogError(SC_ERR_LUAJIT_ERROR, "init function in script should return table, nothing returned"); SCLogError(SC_ERR_LUA_ERROR, "init function in script should return table, nothing returned");
goto error; goto error;
} }
if (lua_type(luastate, 1) != LUA_TTABLE) { if (lua_type(luastate, 1) != LUA_TTABLE) {
SCLogError(SC_ERR_LUAJIT_ERROR, "init function in script should return table, returned is not table"); SCLogError(SC_ERR_LUA_ERROR, "init function in script should return table, returned is not table");
goto error; goto error;
} }
@ -708,7 +708,7 @@ static int DetectLuaSetupPrime(DetectEngineCtx *de_ctx, DetectLuajitData *ld)
lua_pop(luastate, 1); lua_pop(luastate, 1);
if (ld->flowvars == DETECT_LUAJIT_MAX_FLOWVARS) { if (ld->flowvars == DETECT_LUAJIT_MAX_FLOWVARS) {
SCLogError(SC_ERR_LUAJIT_ERROR, "too many flowvars registered"); SCLogError(SC_ERR_LUA_ERROR, "too many flowvars registered");
goto error; goto error;
} }
@ -730,7 +730,7 @@ static int DetectLuaSetupPrime(DetectEngineCtx *de_ctx, DetectLuajitData *ld)
lua_pop(luastate, 1); lua_pop(luastate, 1);
if (ld->flowints == DETECT_LUAJIT_MAX_FLOWINTS) { if (ld->flowints == DETECT_LUAJIT_MAX_FLOWINTS) {
SCLogError(SC_ERR_LUAJIT_ERROR, "too many flowints registered"); SCLogError(SC_ERR_LUA_ERROR, "too many flowints registered");
goto error; goto error;
} }
@ -755,11 +755,11 @@ static int DetectLuaSetupPrime(DetectEngineCtx *de_ctx, DetectLuajitData *ld)
ld->flags |= DATATYPE_PAYLOAD; ld->flags |= DATATYPE_PAYLOAD;
} else if (strncmp(k, "http", 4) == 0 && strcmp(v, "true") == 0) { } else if (strncmp(k, "http", 4) == 0 && strcmp(v, "true") == 0) {
if (ld->alproto != ALPROTO_UNKNOWN && ld->alproto != ALPROTO_HTTP) { if (ld->alproto != ALPROTO_UNKNOWN && ld->alproto != ALPROTO_HTTP) {
SCLogError(SC_ERR_LUAJIT_ERROR, "can just inspect script against one app layer proto like HTTP at a time"); SCLogError(SC_ERR_LUA_ERROR, "can just inspect script against one app layer proto like HTTP at a time");
goto error; goto error;
} }
if (ld->flags != 0) { if (ld->flags != 0) {
SCLogError(SC_ERR_LUAJIT_ERROR, "when inspecting HTTP buffers only a single buffer can be inspected"); SCLogError(SC_ERR_LUA_ERROR, "when inspecting HTTP buffers only a single buffer can be inspected");
goto error; goto error;
} }
@ -803,18 +803,18 @@ static int DetectLuaSetupPrime(DetectEngineCtx *de_ctx, DetectLuajitData *ld)
ld->flags |= DATATYPE_HTTP_RESPONSE_HEADERS_RAW; ld->flags |= DATATYPE_HTTP_RESPONSE_HEADERS_RAW;
else { else {
SCLogError(SC_ERR_LUAJIT_ERROR, "unsupported http data type %s", k); SCLogError(SC_ERR_LUA_ERROR, "unsupported http data type %s", k);
goto error; goto error;
} }
ld->buffername = SCStrdup(k); ld->buffername = SCStrdup(k);
if (ld->buffername == NULL) { if (ld->buffername == NULL) {
SCLogError(SC_ERR_LUAJIT_ERROR, "alloc error"); SCLogError(SC_ERR_LUA_ERROR, "alloc error");
goto error; goto error;
} }
} else { } else {
SCLogError(SC_ERR_LUAJIT_ERROR, "unsupported data type %s", k); SCLogError(SC_ERR_LUA_ERROR, "unsupported data type %s", k);
goto error; goto error;
} }
} }
@ -839,12 +839,12 @@ error:
* \retval 0 on Success * \retval 0 on Success
* \retval -1 on Failure * \retval -1 on Failure
*/ */
static int DetectLuajitSetup (DetectEngineCtx *de_ctx, Signature *s, char *str) static int DetectLuaSetup (DetectEngineCtx *de_ctx, Signature *s, char *str)
{ {
DetectLuajitData *luajit = NULL; DetectLuaData *luajit = NULL;
SigMatch *sm = NULL; SigMatch *sm = NULL;
luajit = DetectLuajitParse(str); luajit = DetectLuaParse(str);
if (luajit == NULL) if (luajit == NULL)
goto error; goto error;
@ -853,8 +853,8 @@ static int DetectLuajitSetup (DetectEngineCtx *de_ctx, Signature *s, char *str)
} }
luajit->thread_ctx_id = DetectRegisterThreadCtxFuncs(de_ctx, "luajit", luajit->thread_ctx_id = DetectRegisterThreadCtxFuncs(de_ctx, "luajit",
DetectLuajitThreadInit, (void *)luajit, DetectLuaThreadInit, (void *)luajit,
DetectLuajitThreadFree, 0); DetectLuaThreadFree, 0);
if (luajit->thread_ctx_id == -1) if (luajit->thread_ctx_id == -1)
goto error; goto error;
@ -871,7 +871,7 @@ static int DetectLuajitSetup (DetectEngineCtx *de_ctx, Signature *s, char *str)
if (sm == NULL) if (sm == NULL)
goto error; goto error;
sm->type = DETECT_LUAJIT; sm->type = DETECT_LUA;
sm->ctx = (void *)luajit; sm->ctx = (void *)luajit;
if (luajit->alproto == ALPROTO_UNKNOWN) if (luajit->alproto == ALPROTO_UNKNOWN)
@ -898,7 +898,7 @@ static int DetectLuajitSetup (DetectEngineCtx *de_ctx, Signature *s, char *str)
else else
SigMatchAppendSMToList(s, sm, DETECT_SM_LIST_AMATCH); SigMatchAppendSMToList(s, sm, DETECT_SM_LIST_AMATCH);
} else { } else {
SCLogError(SC_ERR_LUAJIT_ERROR, "luajit can't be used with protocol %s", SCLogError(SC_ERR_LUA_ERROR, "luajit can't be used with protocol %s",
AppLayerGetProtoName(luajit->alproto)); AppLayerGetProtoName(luajit->alproto));
goto error; goto error;
} }
@ -908,7 +908,7 @@ static int DetectLuajitSetup (DetectEngineCtx *de_ctx, Signature *s, char *str)
error: error:
if (luajit != NULL) if (luajit != NULL)
DetectLuajitFree(luajit); DetectLuaFree(luajit);
if (sm != NULL) if (sm != NULL)
SCFree(sm); SCFree(sm);
return -1; return -1;
@ -917,17 +917,17 @@ error:
/** \brief post-sig parse function to set the sid,rev,gid into the /** \brief post-sig parse function to set the sid,rev,gid into the
* ctx, as this isn't available yet during parsing. * ctx, as this isn't available yet during parsing.
*/ */
void DetectLuajitPostSetup(Signature *s) void DetectLuaPostSetup(Signature *s)
{ {
int i; int i;
SigMatch *sm; SigMatch *sm;
for (i = 0; i < DETECT_SM_LIST_MAX; i++) { for (i = 0; i < DETECT_SM_LIST_MAX; i++) {
for (sm = s->sm_lists[i]; sm != NULL; sm = sm->next) { for (sm = s->sm_lists[i]; sm != NULL; sm = sm->next) {
if (sm->type != DETECT_LUAJIT) if (sm->type != DETECT_LUA)
continue; continue;
DetectLuajitData *ld = sm->ctx; DetectLuaData *ld = sm->ctx;
ld->sid = s->id; ld->sid = s->id;
ld->rev = s->rev; ld->rev = s->rev;
ld->gid = s->gid; ld->gid = s->gid;
@ -936,14 +936,14 @@ void DetectLuajitPostSetup(Signature *s)
} }
/** /**
* \brief this function will free memory associated with DetectLuajitData * \brief this function will free memory associated with DetectLuaData
* *
* \param luajit pointer to DetectLuajitData * \param luajit pointer to DetectLuaData
*/ */
static void DetectLuajitFree(void *ptr) static void DetectLuaFree(void *ptr)
{ {
if (ptr != NULL) { if (ptr != NULL) {
DetectLuajitData *luajit = (DetectLuajitData *)ptr; DetectLuaData *luajit = (DetectLuaData *)ptr;
if (luajit->buffername) if (luajit->buffername)
SCFree(luajit->buffername); SCFree(luajit->buffername);
@ -956,7 +956,7 @@ static void DetectLuajitFree(void *ptr)
#ifdef UNITTESTS #ifdef UNITTESTS
/** \test http buffer */ /** \test http buffer */
static int LuajitMatchTest01(void) static int LuaMatchTest01(void)
{ {
const char script[] = const char script[] =
"function init (args)\n" "function init (args)\n"
@ -1120,7 +1120,7 @@ end:
} }
/** \test payload buffer */ /** \test payload buffer */
static int LuajitMatchTest02(void) static int LuaMatchTest02(void)
{ {
const char script[] = const char script[] =
"function init (args)\n" "function init (args)\n"
@ -1256,7 +1256,7 @@ end:
} }
/** \test packet buffer */ /** \test packet buffer */
static int LuajitMatchTest03(void) static int LuaMatchTest03(void)
{ {
const char script[] = const char script[] =
"function init (args)\n" "function init (args)\n"
@ -1392,7 +1392,7 @@ end:
} }
/** \test http buffer, flowints */ /** \test http buffer, flowints */
static int LuajitMatchTest04(void) static int LuaMatchTest04(void)
{ {
const char script[] = const char script[] =
"function init (args)\n" "function init (args)\n"
@ -1547,7 +1547,7 @@ end:
} }
/** \test http buffer, flowints */ /** \test http buffer, flowints */
static int LuajitMatchTest05(void) static int LuaMatchTest05(void)
{ {
const char script[] = const char script[] =
"function init (args)\n" "function init (args)\n"
@ -1695,7 +1695,7 @@ end:
} }
/** \test http buffer, flowints */ /** \test http buffer, flowints */
static int LuajitMatchTest06(void) static int LuaMatchTest06(void)
{ {
const char script[] = const char script[] =
"function init (args)\n" "function init (args)\n"
@ -1849,17 +1849,16 @@ end:
#endif #endif
void DetectLuajitRegisterTests(void) void DetectLuaRegisterTests(void)
{ {
#ifdef UNITTESTS #ifdef UNITTESTS
UtRegisterTest("LuajitMatchTest01", LuajitMatchTest01, 1); UtRegisterTest("LuaMatchTest01", LuaMatchTest01, 1);
UtRegisterTest("LuajitMatchTest02", LuajitMatchTest02, 1); UtRegisterTest("LuaMatchTest02", LuaMatchTest02, 1);
UtRegisterTest("LuajitMatchTest03", LuajitMatchTest03, 1); UtRegisterTest("LuaMatchTest03", LuaMatchTest03, 1);
UtRegisterTest("LuajitMatchTest04", LuajitMatchTest04, 1); UtRegisterTest("LuaMatchTest04", LuaMatchTest04, 1);
UtRegisterTest("LuajitMatchTest05", LuajitMatchTest05, 1); UtRegisterTest("LuaMatchTest05", LuaMatchTest05, 1);
UtRegisterTest("LuajitMatchTest06", LuajitMatchTest06, 1); UtRegisterTest("LuaMatchTest06", LuaMatchTest06, 1);
#endif #endif
} }
#endif /* HAVE_LUAJIT */ #endif /* HAVE_LUAJIT */

@ -30,16 +30,16 @@
#include <lualib.h> #include <lualib.h>
#include <lauxlib.h> #include <lauxlib.h>
typedef struct DetectLuajitThreadData { typedef struct DetectLuaThreadData {
lua_State *luastate; lua_State *luastate;
uint32_t flags; uint32_t flags;
int alproto; int alproto;
} DetectLuajitThreadData; } DetectLuaThreadData;
#define DETECT_LUAJIT_MAX_FLOWVARS 15 #define DETECT_LUAJIT_MAX_FLOWVARS 15
#define DETECT_LUAJIT_MAX_FLOWINTS 15 #define DETECT_LUAJIT_MAX_FLOWINTS 15
typedef struct DetectLuajitData { typedef struct DetectLuaData {
int thread_ctx_id; int thread_ctx_id;
int negated; int negated;
char *filename; char *filename;
@ -53,17 +53,20 @@ typedef struct DetectLuajitData {
uint32_t sid; uint32_t sid;
uint32_t rev; uint32_t rev;
uint32_t gid; uint32_t gid;
} DetectLuajitData; } DetectLuaData;
#endif /* HAVE_LUA */ #endif /* HAVE_LUA */
/* prototypes */ /* prototypes */
void DetectLuajitRegister (void); void DetectLuaRegister (void);
int DetectLuajitMatchBuffer(DetectEngineThreadCtx *det_ctx, Signature *s, SigMatch *sm, int DetectLuaMatchBuffer(DetectEngineThreadCtx *det_ctx, Signature *s, SigMatch *sm,
uint8_t *buffer, uint32_t buffer_len, uint32_t offset, uint8_t *buffer, uint32_t buffer_len, uint32_t offset,
Flow *f, int flow_lock); Flow *f, int flow_lock);
#ifdef HAVE_LUAJIT
int DetectLuajitSetupStatesPool(int num, int reloads); int DetectLuajitSetupStatesPool(int num, int reloads);
void DetectLuajitPostSetup(Signature *s); #endif /* HAVE_LUAJIT */
void DetectLuaPostSetup(Signature *s);
#endif /* __DETECT_FILELUAJIT_H__ */ #endif /* __DETECT_FILELUAJIT_H__ */

@ -41,7 +41,7 @@
#include "detect-flow.h" #include "detect-flow.h"
#include "detect-app-layer-protocol.h" #include "detect-app-layer-protocol.h"
#include "detect-engine-apt-event.h" #include "detect-engine-apt-event.h"
#include "detect-luajit.h" #include "detect-lua.h"
#include "detect-app-layer-event.h" #include "detect-app-layer-event.h"
#include "pkt-var.h" #include "pkt-var.h"
@ -1319,7 +1319,7 @@ int SigValidate(DetectEngineCtx *de_ctx, Signature *s)
} }
#ifdef HAVE_LUA #ifdef HAVE_LUA
DetectLuajitPostSetup(s); DetectLuaPostSetup(s);
#endif #endif
#ifdef DEBUG #ifdef DEBUG

@ -147,7 +147,7 @@
#include "detect-replace.h" #include "detect-replace.h"
#include "detect-tos.h" #include "detect-tos.h"
#include "detect-app-layer-event.h" #include "detect-app-layer-event.h"
#include "detect-luajit.h" #include "detect-lua.h"
#include "detect-iprep.h" #include "detect-iprep.h"
#include "detect-geoip.h" #include "detect-geoip.h"
#include "detect-dns-query.h" #include "detect-dns-query.h"
@ -4808,7 +4808,7 @@ void SigTableSetup(void)
DetectHttpUARegister(); DetectHttpUARegister();
DetectHttpHHRegister(); DetectHttpHHRegister();
DetectHttpHRHRegister(); DetectHttpHRHRegister();
DetectLuajitRegister(); DetectLuaRegister();
DetectIPRepRegister(); DetectIPRepRegister();
DetectDnsQueryRegister(); DetectDnsQueryRegister();
DetectAppLayerProtocolRegister(); DetectAppLayerProtocolRegister();

@ -1136,7 +1136,7 @@ enum {
DETECT_FILESIZE, DETECT_FILESIZE,
DETECT_L3PROTO, DETECT_L3PROTO,
DETECT_LUAJIT, DETECT_LUA,
DETECT_IPREP, DETECT_IPREP,
DETECT_AL_DNS_QUERY, DETECT_AL_DNS_QUERY,

@ -383,14 +383,14 @@ static int LuaScriptInit(const char *filename, LogLuaScriptOptions *options) {
if (ut_script != NULL) { if (ut_script != NULL) {
status = luaL_loadbuffer(luastate, ut_script, strlen(ut_script), "unittest"); status = luaL_loadbuffer(luastate, ut_script, strlen(ut_script), "unittest");
if (status) { if (status) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't load file: %s", lua_tostring(luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't load file: %s", lua_tostring(luastate, -1));
goto error; goto error;
} }
} else { } else {
#endif #endif
status = luaL_loadfile(luastate, filename); status = luaL_loadfile(luastate, filename);
if (status) { if (status) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't load file: %s", lua_tostring(luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't load file: %s", lua_tostring(luastate, -1));
goto error; goto error;
} }
#if 0//def UNITTESTS #if 0//def UNITTESTS
@ -399,19 +399,19 @@ static int LuaScriptInit(const char *filename, LogLuaScriptOptions *options) {
/* prime the script (or something) */ /* prime the script (or something) */
if (lua_pcall(luastate, 0, 0, 0) != 0) { if (lua_pcall(luastate, 0, 0, 0) != 0) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't prime file: %s", lua_tostring(luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't prime file: %s", lua_tostring(luastate, -1));
goto error; goto error;
} }
lua_getglobal(luastate, "init"); lua_getglobal(luastate, "init");
if (lua_type(luastate, -1) != LUA_TFUNCTION) { if (lua_type(luastate, -1) != LUA_TFUNCTION) {
SCLogError(SC_ERR_LUAJIT_ERROR, "no init function in script"); SCLogError(SC_ERR_LUA_ERROR, "no init function in script");
goto error; goto error;
} }
lua_newtable(luastate); /* stack at -1 */ lua_newtable(luastate); /* stack at -1 */
if (lua_gettop(luastate) == 0 || lua_type(luastate, 2) != LUA_TTABLE) { if (lua_gettop(luastate) == 0 || lua_type(luastate, 2) != LUA_TTABLE) {
SCLogError(SC_ERR_LUAJIT_ERROR, "no table setup"); SCLogError(SC_ERR_LUA_ERROR, "no table setup");
goto error; goto error;
} }
@ -420,17 +420,17 @@ static int LuaScriptInit(const char *filename, LogLuaScriptOptions *options) {
lua_settable(luastate, -3); lua_settable(luastate, -3);
if (lua_pcall(luastate, 1, 1, 0) != 0) { if (lua_pcall(luastate, 1, 1, 0) != 0) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't run script 'init' function: %s", lua_tostring(luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't run script 'init' function: %s", lua_tostring(luastate, -1));
goto error; goto error;
} }
/* process returns from script */ /* process returns from script */
if (lua_gettop(luastate) == 0) { if (lua_gettop(luastate) == 0) {
SCLogError(SC_ERR_LUAJIT_ERROR, "init function in script should return table, nothing returned"); SCLogError(SC_ERR_LUA_ERROR, "init function in script should return table, nothing returned");
goto error; goto error;
} }
if (lua_type(luastate, 1) != LUA_TTABLE) { if (lua_type(luastate, 1) != LUA_TTABLE) {
SCLogError(SC_ERR_LUAJIT_ERROR, "init function in script should return table, returned is not table"); SCLogError(SC_ERR_LUA_ERROR, "init function in script should return table, returned is not table");
goto error; goto error;
} }
@ -467,25 +467,25 @@ static int LuaScriptInit(const char *filename, LogLuaScriptOptions *options) {
} }
if (options->alproto + options->packet + options->file > 1) { if (options->alproto + options->packet + options->file > 1) {
SCLogError(SC_ERR_LUAJIT_ERROR, "invalid combination of 'needs' in the script"); SCLogError(SC_ERR_LUA_ERROR, "invalid combination of 'needs' in the script");
goto error; goto error;
} }
lua_getglobal(luastate, "setup"); lua_getglobal(luastate, "setup");
if (lua_type(luastate, -1) != LUA_TFUNCTION) { if (lua_type(luastate, -1) != LUA_TFUNCTION) {
SCLogError(SC_ERR_LUAJIT_ERROR, "no setup function in script"); SCLogError(SC_ERR_LUA_ERROR, "no setup function in script");
goto error; goto error;
} }
lua_getglobal(luastate, "log"); lua_getglobal(luastate, "log");
if (lua_type(luastate, -1) != LUA_TFUNCTION) { if (lua_type(luastate, -1) != LUA_TFUNCTION) {
SCLogError(SC_ERR_LUAJIT_ERROR, "no log function in script"); SCLogError(SC_ERR_LUA_ERROR, "no log function in script");
goto error; goto error;
} }
lua_getglobal(luastate, "deinit"); lua_getglobal(luastate, "deinit");
if (lua_type(luastate, -1) != LUA_TFUNCTION) { if (lua_type(luastate, -1) != LUA_TFUNCTION) {
SCLogError(SC_ERR_LUAJIT_ERROR, "no deinit function in script"); SCLogError(SC_ERR_LUA_ERROR, "no deinit function in script");
goto error; goto error;
} }
@ -508,7 +508,7 @@ static lua_State *LuaScriptSetup(const char *filename)
{ {
lua_State *luastate = luaL_newstate(); lua_State *luastate = luaL_newstate();
if (luastate == NULL) { if (luastate == NULL) {
SCLogError(SC_ERR_LUAJIT_ERROR, "luaL_newstate failed"); SCLogError(SC_ERR_LUA_ERROR, "luaL_newstate failed");
goto error; goto error;
} }
@ -520,14 +520,14 @@ static lua_State *LuaScriptSetup(const char *filename)
if (ut_script != NULL) { if (ut_script != NULL) {
status = luaL_loadbuffer(t->luastate, ut_script, strlen(ut_script), "unittest"); status = luaL_loadbuffer(t->luastate, ut_script, strlen(ut_script), "unittest");
if (status) { if (status) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't load file: %s", lua_tostring(t->luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't load file: %s", lua_tostring(t->luastate, -1));
goto error; goto error;
} }
} else { } else {
#endif #endif
status = luaL_loadfile(luastate, filename); status = luaL_loadfile(luastate, filename);
if (status) { if (status) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't load file: %s", lua_tostring(luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't load file: %s", lua_tostring(luastate, -1));
goto error; goto error;
} }
#if 0//def UNITTESTS #if 0//def UNITTESTS
@ -536,7 +536,7 @@ static lua_State *LuaScriptSetup(const char *filename)
/* prime the script */ /* prime the script */
if (lua_pcall(luastate, 0, 0, 0) != 0) { if (lua_pcall(luastate, 0, 0, 0) != 0) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't prime file: %s", lua_tostring(luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't prime file: %s", lua_tostring(luastate, -1));
goto error; goto error;
} }
@ -549,7 +549,7 @@ static lua_State *LuaScriptSetup(const char *filename)
LogLuaRegisterHttpFunctions(luastate); LogLuaRegisterHttpFunctions(luastate);
if (lua_pcall(luastate, 0, 0, 0) != 0) { if (lua_pcall(luastate, 0, 0, 0) != 0) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't run script 'setup' function: %s", lua_tostring(luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't run script 'setup' function: %s", lua_tostring(luastate, -1));
goto error; goto error;
} }
@ -633,7 +633,7 @@ static OutputCtx *OutputLuaLogInit(ConfNode *conf)
int r = LuaScriptInit(script->val, &opts); int r = LuaScriptInit(script->val, &opts);
if (r != 0) { if (r != 0) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't initialize scipt"); SCLogError(SC_ERR_LUA_ERROR, "couldn't initialize scipt");
continue; continue;
} }
@ -668,7 +668,7 @@ static OutputCtx *OutputLuaLogInit(ConfNode *conf)
} else if (opts.flow) { } else if (opts.flow) {
om->FlowLogFunc = LuaFlowLogger; om->FlowLogFunc = LuaFlowLogger;
} else { } else {
SCLogError(SC_ERR_LUAJIT_ERROR, "failed to setup thread module"); SCLogError(SC_ERR_LUA_ERROR, "failed to setup thread module");
SCFree(om); SCFree(om);
continue; continue;
} }
@ -688,13 +688,13 @@ static void OutputLuaLogDoDeinit(LogLuaCtx *lua_ctx)
lua_getglobal(luastate, "deinit"); lua_getglobal(luastate, "deinit");
if (lua_type(luastate, -1) != LUA_TFUNCTION) { if (lua_type(luastate, -1) != LUA_TFUNCTION) {
SCLogError(SC_ERR_LUAJIT_ERROR, "no deinit function in script"); SCLogError(SC_ERR_LUA_ERROR, "no deinit function in script");
return; return;
} }
//LuaPrintStack(luastate); //LuaPrintStack(luastate);
if (lua_pcall(luastate, 0, 0, 0) != 0) { if (lua_pcall(luastate, 0, 0, 0) != 0) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't run script 'deinit' function: %s", lua_tostring(luastate, -1)); SCLogError(SC_ERR_LUA_ERROR, "couldn't run script 'deinit' function: %s", lua_tostring(luastate, -1));
return; return;
} }
} }

@ -251,8 +251,8 @@ const char * SCErrorToString(SCError err)
CASE_CODE (SC_ERR_INVALID_MD5); CASE_CODE (SC_ERR_INVALID_MD5);
CASE_CODE (SC_ERR_NO_MD5_SUPPORT); CASE_CODE (SC_ERR_NO_MD5_SUPPORT);
CASE_CODE (SC_ERR_EVENT_ENGINE); CASE_CODE (SC_ERR_EVENT_ENGINE);
CASE_CODE (SC_ERR_NO_LUAJIT_SUPPORT); CASE_CODE (SC_ERR_NO_LUA_SUPPORT);
CASE_CODE (SC_ERR_LUAJIT_ERROR); CASE_CODE (SC_ERR_LUA_ERROR);
CASE_CODE (SC_ERR_NO_GEOIP_SUPPORT); CASE_CODE (SC_ERR_NO_GEOIP_SUPPORT);
CASE_CODE (SC_ERR_GEOIP_ERROR); CASE_CODE (SC_ERR_GEOIP_ERROR);
CASE_CODE (SC_ERR_DEFRAG_INIT); CASE_CODE (SC_ERR_DEFRAG_INIT);

@ -240,8 +240,8 @@ typedef enum {
SC_ERR_INVALID_MD5, SC_ERR_INVALID_MD5,
SC_ERR_NO_MD5_SUPPORT, SC_ERR_NO_MD5_SUPPORT,
SC_ERR_EVENT_ENGINE, SC_ERR_EVENT_ENGINE,
SC_ERR_NO_LUAJIT_SUPPORT, SC_ERR_NO_LUA_SUPPORT,
SC_ERR_LUAJIT_ERROR, SC_ERR_LUA_ERROR,
SC_ERR_DEFRAG_INIT, SC_ERR_DEFRAG_INIT,
SC_ERR_NAPATECH_OPEN_FAILED, SC_ERR_NAPATECH_OPEN_FAILED,
SC_ERR_NAPATECH_STREAM_NEXT_FAILED, SC_ERR_NAPATECH_STREAM_NEXT_FAILED,

Loading…
Cancel
Save