]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
lua/luajit: use HAVE_LUA mostly 980/head
authorVictor Julien <victor@inliniac.net>
Thu, 13 Mar 2014 15:24:51 +0000 (16:24 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 2 Jun 2014 15:00:16 +0000 (17:00 +0200)
Only use HAVE_LUAJIT if things are done differently from HAVE_LUA,
like in the states pool.

src/detect-engine-content-inspection.c
src/detect-luajit-extensions.c
src/detect-luajit-extensions.h
src/detect-luajit.c
src/detect-luajit.h
src/detect-parse.c
src/suricata.c

index bc05e8eb44d6fa426ced090572a6483234579840..69d8b0192bbe16162150cadcc65a3386ee0cdf7f 100644 (file)
@@ -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
index 10b74d42379b1781ecb2de2487899fb954a56e8d..0fa3aced21c00b935bd11bea3e44efdd0faee120 100644 (file)
@@ -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 */
index 87f3c056adb415641f9deaf70da3a61fda0a7953..c8e678d750ec2691866ef4aef6c2da5367e206bf 100644 (file)
 #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
index bae31fcdfa88bebc2cbc53357db3c77c606b8a45..0d1aff6176e01c0376c67da7abe5c92c4d3104bd 100644 (file)
@@ -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
     }
 }
 
index 00ce65060826d45c8bc465b1ff841ee59ee6e5f2..55eb9bde89f396934fc52fcfcb4fb49457acc23c 100644 (file)
@@ -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);
index f147d0c798289772ac1efaa74eebb18b8339e158..77f50e9f36369464caaebd83e9066d3f6bae22fb 100644 (file)
@@ -1301,7 +1301,7 @@ int SigValidate(DetectEngineCtx *de_ctx, Signature *s) {
         }
     }
 
-#ifdef HAVE_LUAJIT
+#ifdef HAVE_LUA
     DetectLuajitPostSetup(s);
 #endif
 
index 013fac6194de7ecc95bb2006a1989ad9d0757137..b1691cfc178f8fbaa03617d6a2beb9215a49ab63 100644 (file)
@@ -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