lua/luajit: use HAVE_LUA mostly

Only use HAVE_LUAJIT if things are done differently from HAVE_LUA,
like in the states pool.
pull/980/head
Victor Julien 12 years ago
parent 7396237c2a
commit 25cbf36d40

@ -529,10 +529,10 @@ int DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx
det_ctx->discontinue_matching = 0;
goto no_match;
#ifdef HAVE_LUAJIT
#ifdef HAVE_LUA
}
else if (sm->type == DETECT_LUAJIT) {
SCLogDebug("luajit starting");
SCLogDebug("lua starting");
/* for flowvar gets and sets we need to know the flow's lock status */
int need_flow_lock = 0;
if (inspection_mode <= DETECT_ENGINE_CONTENT_INSPECTION_MODE_STREAM)
@ -541,12 +541,12 @@ int DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx
if (DetectLuajitMatchBuffer(det_ctx, s, sm, buffer, buffer_len,
det_ctx->buffer_offset, f, need_flow_lock) != 1)
{
SCLogDebug("luajit no_match");
SCLogDebug("lua no_match");
goto no_match;
}
SCLogDebug("luajit match");
SCLogDebug("lua match");
goto match;
#endif
#endif /* HAVE_LUA */
} else {
SCLogDebug("sm->type %u", sm->type);
#ifdef DEBUG

@ -58,7 +58,7 @@
#include "queue.h"
#include "util-cpu.h"
#ifdef HAVE_LUAJIT
#ifdef HAVE_LUA
static const char luaext_key_ld[] = "suricata:luajitdata";
static const char luaext_key_det_ctx[] = "suricata:det_ctx";
@ -658,4 +658,4 @@ int LuajitRegisterExtensions(lua_State *lua_state) {
return 0;
}
#endif /* HAVE_LUAJIT */
#endif /* HAVE_LUA */

@ -24,12 +24,12 @@
#ifndef __DETECT_LUAJIT_EXT_H__
#define __DETECT_LUAJIT_EXT_H__
#ifdef HAVE_LUAJIT
#ifdef HAVE_LUA
int LuajitRegisterExtensions(lua_State *);
void LuajitExtensionsMatchSetup(lua_State *lua_state,
DetectLuajitData *, DetectEngineThreadCtx *det_ctx,
Flow *f, int need_flow_lock);
#endif /* HAVE_LUAJIT */
#endif /* HAVE_LUA */
#endif

@ -59,7 +59,7 @@
#include "util-cpu.h"
#include "util-var-name.h"
#ifndef HAVE_LUAJIT
#ifndef HAVE_LUA
static int DetectLuajitSetupNoSupport (DetectEngineCtx *a, Signature *b, char *c) {
SCLogError(SC_ERR_NO_LUAJIT_SUPPORT, "no LuaJIT support built in, needed for luajit keyword");
@ -81,10 +81,28 @@ void DetectLuajitRegister(void) {
return;
}
#else /* HAVE_LUAJIT */
#else /* HAVE_LUA */
#ifdef HAVE_LUAJIT
#include "util-pool.h"
/** \brief lua_State pool
*
* Luajit 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
* of getting the states. We protect the pool with a lock as the detect
* threads access it during their init and cleanup.
*
* Pool size is automagically determined based on number of keyword occurences,
* cpus/cores and rule reloads being enabled or not.
*
* Alternatively, the "detect-engine.luajit-states" var can be set.
*/
static Pool *luajit_states = NULL;
static pthread_mutex_t luajit_states_lock = SCMUTEX_INITIALIZER;
#endif /* HAVE_LUAJIT */
static int DetectLuajitMatch (ThreadVars *, DetectEngineThreadCtx *,
Packet *, Signature *, SigMatch *);
static int DetectLuajitSetup (DetectEngineCtx *, Signature *, char *);
@ -108,21 +126,6 @@ void DetectLuajitRegister(void) {
return;
}
/** \brief lua_State pool
*
* Luajit 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
* of getting the states. We protect the pool with a lock as the detect
* threads access it during their init and cleanup.
*
* Pool size is automagically determined based on number of keyword occurences,
* cpus/cores and rule reloads being enabled or not.
*
* Alternatively, the "detect-engine.luajit-states" var can be set.
*/
static Pool *luajit_states = NULL;
static pthread_mutex_t luajit_states_lock = SCMUTEX_INITIALIZER;
#define DATATYPE_PACKET (1<<0)
#define DATATYPE_PAYLOAD (1<<1)
#define DATATYPE_STREAM (1<<2)
@ -144,6 +147,7 @@ static pthread_mutex_t luajit_states_lock = SCMUTEX_INITIALIZER;
#define DATATYPE_HTTP_RESPONSE_HEADERS (1<<13)
#define DATATYPE_HTTP_RESPONSE_HEADERS_RAW (1<<14)
#ifdef HAVE_LUAJIT
static void *LuaStatePoolAlloc(void) {
return luaL_newstate();
}
@ -192,22 +196,31 @@ int DetectLuajitSetupStatesPool(int num, int reloads) {
pthread_mutex_unlock(&luajit_states_lock);
return retval;
}
#endif /* HAVE_LUAJIT */
static lua_State *DetectLuajitGetState(void) {
lua_State *s = NULL;
#ifdef HAVE_LUAJIT
pthread_mutex_lock(&luajit_states_lock);
if (luajit_states != NULL)
s = (lua_State *)PoolGet(luajit_states);
pthread_mutex_unlock(&luajit_states_lock);
#else
s = luaL_newstate();
#endif
return s;
}
static void DetectLuajitReturnState(lua_State *s) {
if (s != NULL) {
#ifdef HAVE_LUAJIT
pthread_mutex_lock(&luajit_states_lock);
PoolReturn(luajit_states, (void *)s);
pthread_mutex_unlock(&luajit_states_lock);
#else
lua_close(s);
#endif
}
}

@ -24,7 +24,7 @@
#ifndef __DETECT_LUAJIT_H__
#define __DETECT_LUAJIT_H__
#ifdef HAVE_LUAJIT
#ifdef HAVE_LUA
#include <lua.h>
#include <lualib.h>
@ -54,7 +54,8 @@ typedef struct DetectLuajitData {
uint32_t rev;
uint32_t gid;
} DetectLuajitData;
#endif
#endif /* HAVE_LUA */
/* prototypes */
void DetectLuajitRegister (void);

@ -1301,7 +1301,7 @@ int SigValidate(DetectEngineCtx *de_ctx, Signature *s) {
}
}
#ifdef HAVE_LUAJIT
#ifdef HAVE_LUA
DetectLuajitPostSetup(s);
#endif

@ -669,6 +669,9 @@ void SCPrintBuildInfo(void) {
#ifdef HAVE_NSS
strlcat(features, "HAVE_NSS ", sizeof(features));
#endif
#ifdef HAVE_LUA
strlcat(features, "HAVE_LUA ", sizeof(features));
#endif
#ifdef HAVE_LUAJIT
strlcat(features, "HAVE_LUAJIT ", sizeof(features));
#endif

Loading…
Cancel
Save