]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
lua: Remove luajit support
authorJo Johnson <pyrojoe314@gmail.com>
Fri, 12 Jan 2024 19:37:03 +0000 (11:37 -0800)
committerJason Ish <jason.ish@oisf.net>
Mon, 27 May 2024 22:00:17 +0000 (16:00 -0600)
lua 5.4 support is not available in luajit

Ticket: #4776

configure.ac
doc/userguide/configuration/suricata-yaml.rst
doc/userguide/rules/differences-from-snort.rst
src/Makefile.am
src/detect-lua.c
src/runmode-unittests.c
src/suricata.c
src/util-lua.c
src/util-luajit.c [deleted file]
src/util-luajit.h [deleted file]
suricata.yaml.in

index c6b38efc2522a1247972c14ea55a46b01d08b683..b458718ffb1ad450f459ec41275af50c0f996853 100644 (file)
   # liblua
     AC_ARG_ENABLE(lua,
             AS_HELP_STRING([--enable-lua],[Enable Lua support]),
-            [ enable_lua="$enableval"],
-            [ enable_lua="no"])
-    AC_ARG_ENABLE(luajit,
-            AS_HELP_STRING([--enable-luajit],[Enable Luajit support]),
-            [ enable_luajit="$enableval"],
-            [ enable_luajit="no"])
-    if test "$enable_lua" = "yes"; then
-        if test "$enable_luajit" = "yes"; then
-            echo "ERROR: can't enable liblua and luajit at the same time."
-            echo "For LuaJIT, just use --enable-luajit. For liblua (no jit)"
-            echo "support, use just --enable-lua."
-            echo "Both options will enable the Lua scripting capabilities"
-            echo "in Suricata".
-            echo
-            exit 1
-        fi
-    fi
+                [ enable_lua="$enableval"],
+                [ enable_lua="no"])
 
     AC_ARG_WITH(liblua_includes,
             [  --with-liblua-includes=DIR  liblua include directory],
         fi
     fi
 
-  # libluajit
-    AC_ARG_WITH(libluajit_includes,
-            [  --with-libluajit-includes=DIR  libluajit include directory],
-            [with_libluajit_includes="$withval"],[with_libluajit_includes="no"])
-    AC_ARG_WITH(libluajit_libraries,
-            [  --with-libluajit-libraries=DIR    libluajit library directory],
-            [with_libluajit_libraries="$withval"],[with_libluajit_libraries="no"])
-
-    if test "$enable_luajit" = "yes"; then
-        if test "$with_libluajit_includes" != "no"; then
-            CPPFLAGS="${CPPFLAGS} -I${with_libluajit_includes}"
-        else
-            PKG_CHECK_MODULES([LUAJIT], [luajit], , LUAJIT="no")
-            CPPFLAGS="${CPPFLAGS} ${LUAJIT_CFLAGS}"
-        fi
-
-        AC_CHECK_HEADER(lualib.h,LUAJIT="yes",LUAJIT="no")
-        if test "$LUAJIT" = "yes"; then
-            if test "$with_libluajit_libraries" != "no"; then
-                LDFLAGS="${LDFLAGS}  -L${with_libluajit_libraries}"
-            else
-                PKG_CHECK_MODULES([LUAJIT], [luajit])
-                LIBS="${LIBS} ${LUAJIT_LIBS}"
-            fi
-
-            AC_CHECK_LIB(luajit-5.1, luaL_openlibs,, LUAJIT="no")
-
-            if test "$LUAJIT" = "no"; then
-                echo
-                echo "   ERROR!  libluajit library not found, go get it"
-                echo "   from http://luajit.org/index.html or your distribution:"
-                echo
-                echo "   Ubuntu: apt-get install libluajit-5.1-dev"
-                echo
-                echo "   If you installed software in a non-standard prefix"
-                echo "   consider adjusting the PKG_CONFIG_PATH environment variable"
-                echo "   or use --with-libluajit-libraries configure option."
-                echo
-                exit 1
-            fi
-
-            AC_DEFINE([HAVE_LUA],[1],[lua support available])
-            AC_DEFINE([HAVE_LUAJIT],[1],[libluajit available])
-            enable_lua="yes, through luajit"
-            enable_luajit="yes"
-        else
-            echo
-                echo "   ERROR!  libluajit headers not found, go get them"
-                echo "   from http://luajit.org/index.html or your distribution:"
-                echo
-                echo "   Ubuntu: apt-get install libluajit-5.1-dev"
-                echo
-                echo "   If you installed software in a non-standard prefix"
-                echo "   consider adjusting the PKG_CONFIG_PATH environment variable"
-                echo "   or use --with-libluajit-includes and --with-libluajit-libraries"
-                echo "   configure option."
-                echo
-                exit 1
-        fi
-    fi
-
     AM_CONDITIONAL([HAVE_LUA], [test "x$enable_lua" != "xno"])
 
     # If Lua is enabled, test the integer size.
@@ -2695,7 +2619,6 @@ SURICATA_BUILD_CONF="Suricata Configuration:
   hiredis async with libevent:             ${enable_hiredis_async}
   PCRE jit:                                ${pcre2_jit_available}
   LUA support:                             ${enable_lua}
-  libluajit:                               ${enable_luajit}
   GeoIP2 support:                          ${enable_geoip}
   JA3 support:                             ${enable_ja3}
   JA4 support:                             ${enable_ja4}
index 75fdcd041b2b7a251197012c21c9642386d7330c..0d075ea3c9738554cb29229d0cff8dea6f6d73cd 100644 (file)
@@ -2759,24 +2759,6 @@ to display the diagnostic message if a signal unexpectedly terminates Suricata -
         # message with the offending stacktrace if enabled.
         #stacktrace-on-signal: on
 
-luajit
-~~~~~~
-
-states
-^^^^^^
-
-Luajit has a strange memory requirement, it's 'states' need to be in the
-first 2G of the process' memory. For this reason when luajit is used the
-states are allocated at the process startup. This option controls how many
-states are preallocated.
-
-If the pool is depleted a warning is generated. Suricata will still try to
-continue, but may fail if other parts of the engine take too much memory.
-If the pool was depleted a hint will be printed at the engines exit.
-
-States are allocated as follows: for each detect script a state is used per
-detect thread. For each output script, a single state is used. Keep in
-mind that a rule reload temporary doubles the states requirement.
 
 .. _deprecation policy: https://suricata.io/about/deprecation-policy/
 
index a32966c4284b7868b9f28ffc8693aa8aacb75fb4..07adbafbabbea9a6393a05a5f1e5f96613c1b607 100644 (file)
@@ -525,7 +525,7 @@ File Extraction
 Lua Scripting
 -------------
 
--  Suricata has the ``lua`` (or ``luajit``) keyword which allows for a
+-  Suricata has the ``lua`` keyword which allows for a
    rule to reference a Lua script that can access the packet, payload,
    HTTP buffers, etc.
 -  Provides powerful flexibility and capabilities that Snort does
index ee4c32090696493fb84e8f6757651fdd9595dc7c..65ebc0216632edd3ed8d8f9083c11a0761ee282d 100755 (executable)
@@ -562,7 +562,6 @@ noinst_HEADERS = \
        util-lua-hassh.h \
        util-lua-http.h \
        util-lua-ja3.h \
-       util-luajit.h \
        util-lua-smtp.h \
        util-lua-ssh.h \
        util-lua-tls.h \
@@ -1156,7 +1155,6 @@ libsuricata_c_a_SOURCES = \
        util-lua-hassh.c \
        util-lua-http.c \
        util-lua-ja3.c \
-       util-luajit.c \
        util-lua-smtp.c \
        util-lua-ssh.c \
        util-lua-tls.c \
index 889d57f4897b9155527ccd008876c576e88e6064..a6d334537dd8a3f0d8335011b64ad39b71e1ddd9 100644 (file)
@@ -2423,4 +2423,4 @@ void DetectLuaRegisterTests(void)
     UtRegisterTest("LuaMatchTest06a", LuaMatchTest06a);
 }
 #endif
-#endif /* HAVE_LUAJIT */
+#endif /* HAVE_LUA */
index 30d2021bfced89ec87bc1672eeb8c5fa1e539378..ec33efe975726592d73382cf05b21c5aa534cb1b 100644 (file)
 
 #include "util-streaming-buffer.h"
 #include "util-lua.h"
-#include "util-luajit.h"
 #include "tm-modules.h"
 #include "tmqh-packetpool.h"
 #include "decode-chdlc.h"
@@ -235,12 +234,6 @@ void RunUnittests(int list_unittests, const char *regex_arg)
     GlobalsInitPreConfig();
     EngineModeSetIDS();
 
-#ifdef HAVE_LUAJIT
-    if (LuajitSetupStatesPool() != 0) {
-        exit(EXIT_FAILURE);
-    }
-#endif
-
     default_packet_size = DEFAULT_PACKET_SIZE;
     /* load the pattern matchers */
     MpmTableSetup();
@@ -292,10 +285,6 @@ void RunUnittests(int list_unittests, const char *regex_arg)
         }
     }
 
-#ifdef HAVE_LUAJIT
-    LuajitFreeStatesPool();
-#endif
-
     exit(EXIT_SUCCESS);
 #else
     FatalError("Unittests are not build-in");
index 6d316771f9a06337c404542d80607217b240364f..e29a3a0177003fa49a46d4fd5927acd0f8a3fcaf 100644 (file)
 #include "util-hugepages.h"
 #include "util-ioctl.h"
 #include "util-landlock.h"
-#include "util-luajit.h"
 #include "util-macset.h"
 #include "util-misc.h"
 #include "util-mpm-hs.h"
@@ -415,9 +414,7 @@ void GlobalsDestroy(void)
 #endif
 
     ConfDeInit();
-#ifdef HAVE_LUAJIT
-    LuajitFreeStatesPool();
-#endif
+
     DetectParseFreeRegexes();
 
     SCPidfileRemove(suri->pid_filename);
@@ -751,9 +748,6 @@ static void PrintBuildInfo(void)
 #endif
 #ifdef HAVE_JA4
     strlcat(features, "HAVE_JA4 ", sizeof(features));
-#endif
-#ifdef HAVE_LUAJIT
-    strlcat(features, "HAVE_LUAJIT ", sizeof(features));
 #endif
     strlcat(features, "HAVE_LIBJANSSON ", sizeof(features));
 #ifdef PROFILING
@@ -2637,13 +2631,6 @@ static void SetupUserMode(SCInstance *suri)
  */
 int PostConfLoadedSetup(SCInstance *suri)
 {
-    /* do this as early as possible #1577 #1955 */
-#ifdef HAVE_LUAJIT
-    if (LuajitSetupStatesPool() != 0) {
-        SCReturnInt(TM_ECODE_FAILED);
-    }
-#endif
-
     /* load the pattern matchers */
     MpmTableSetup();
     SpmTableSetup();
index 9e65c3017fcb712ae0cdf4c5e6ce8197b6c00361..d903f44e39df0990e04645c32f34bda34d55d430 100644 (file)
@@ -34,7 +34,6 @@
 
 #include "util-print.h"
 #include "util-unittest.h"
-#include "util-luajit.h"
 
 #include "util-debug.h"
 
 lua_State *LuaGetState(void)
 {
     lua_State *s = NULL;
-#ifdef HAVE_LUAJIT
-    s = LuajitGetState();
-#else
     s = luaL_newstate();
-#endif
     return s;
 }
 
@@ -74,11 +69,7 @@ void LuaReturnState(lua_State *s)
         while (lua_gettop(s) > 0) {
             lua_pop(s, 1);
         }
-#ifdef HAVE_LUAJIT
-        LuajitReturnState(s);
-#else
         lua_close(s);
-#endif
     }
 }
 
diff --git a/src/util-luajit.c b/src/util-luajit.c
deleted file mode 100644 (file)
index a089e13..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/* Copyright (C) 2007-2016 Open Information Security Foundation
- *
- * You can copy, redistribute or modify this Program under the terms of
- * the GNU General Public License version 2 as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-
-/**
- * \file
- *
- * \author Victor Julien <victor@inliniac.net>
- *
- */
-
-#include "suricata-common.h"
-
-#ifdef HAVE_LUAJIT
-#include "conf.h"
-#include "util-pool.h"
-#include "util-lua.h"
-#include "util-luajit.h"
-
-/** \brief lua_State pool
- *
- *  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
- *  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 occurrences,
- *  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;
-static int luajit_states_cnt = 0;
-static int luajit_states_cnt_max = 0;
-static int luajit_states_size = 0;
-#define LUAJIT_DEFAULT_STATES 128
-
-static void *LuaStatePoolAlloc(void)
-{
-    return luaL_newstate();
-}
-
-static void LuaStatePoolFree(void *d)
-{
-    lua_State *s = (lua_State *)d;
-    if (s != NULL)
-        lua_close(s);
-}
-
-/** \brief Populate lua states pool
- *
- *  \param num keyword instances
- *  \param reloads bool indicating we have rule reloads enabled
- */
-int LuajitSetupStatesPool(void)
-{
-    int retval = 0;
-    pthread_mutex_lock(&luajit_states_lock);
-
-    if (luajit_states == NULL) {
-        intmax_t cnt = 0;
-        if (ConfGetInt("luajit.states", &cnt) != 1) {
-            ConfNode *denode = NULL;
-            ConfNode *decnf = ConfGetNode("detect-engine");
-            if (decnf != NULL) {
-                TAILQ_FOREACH(denode, &decnf->head, next) {
-                    if (denode->val && strcmp(denode->val, "luajit-states") == 0) {
-                        ConfGetChildValueInt(denode, "luajit-states", &cnt);
-                    }
-                }
-            }
-        }
-        if (cnt == 0) {
-            cnt = LUAJIT_DEFAULT_STATES;
-        }
-        luajit_states_size = cnt;
-
-        luajit_states = PoolInit(0, cnt, 0, LuaStatePoolAlloc, NULL, NULL, NULL, LuaStatePoolFree);
-        if (luajit_states == NULL) {
-            SCLogError("luastate pool init failed, lua/luajit keywords won't work");
-            retval = -1;
-        }
-
-        if (retval == 0) {
-            SCLogConfig("luajit states preallocated: %d", luajit_states_size);
-        }
-    }
-
-    pthread_mutex_unlock(&luajit_states_lock);
-    return retval;
-}
-
-void LuajitFreeStatesPool(void)
-{
-    pthread_mutex_lock(&luajit_states_lock);
-    if (luajit_states_cnt_max > luajit_states_size) {
-        SCLogNotice("luajit states used %d is bigger than pool size %d. Set "
-                    "luajit.states to %d to avoid memory issues. "
-                    "See tickets #1577 and #1955.",
-                luajit_states_cnt_max, luajit_states_size, luajit_states_cnt_max);
-    }
-    PoolFree(luajit_states);
-    luajit_states = NULL;
-    luajit_states_size = 0;
-    luajit_states_cnt = 0;
-    pthread_mutex_unlock(&luajit_states_lock);
-}
-
-lua_State *LuajitGetState(void)
-{
-    lua_State *s = NULL;
-    pthread_mutex_lock(&luajit_states_lock);
-    if (luajit_states != NULL) {
-        s = (lua_State *)PoolGet(luajit_states);
-        if (s != NULL) {
-            if (luajit_states_cnt == luajit_states_size) {
-                SCLogWarning("luajit states pool size %d "
-                             "reached. Increase luajit.states config option. "
-                             "See tickets #1577 and #1955",
-                        luajit_states_size);
-            }
-
-            luajit_states_cnt++;
-            if (luajit_states_cnt > luajit_states_cnt_max)
-                luajit_states_cnt_max = luajit_states_cnt;
-        }
-    }
-    pthread_mutex_unlock(&luajit_states_lock);
-    return s;
-}
-
-void LuajitReturnState(lua_State *s)
-{
-    if (s != NULL) {
-        pthread_mutex_lock(&luajit_states_lock);
-        PoolReturn(luajit_states, (void *)s);
-        BUG_ON(luajit_states_cnt <= 0);
-        luajit_states_cnt--;
-        pthread_mutex_unlock(&luajit_states_lock);
-    }
-}
-
-#endif /* HAVE_LUAJIT */
diff --git a/src/util-luajit.h b/src/util-luajit.h
deleted file mode 100644 (file)
index 83964f6..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/* Copyright (C) 2007-2016 Open Information Security Foundation
- *
- * You can copy, redistribute or modify this Program under the terms of
- * the GNU General Public License version 2 as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-
-/**
- * \file
- *
- * \author Victor Julien <victor@inliniac.net>
- */
-
-#ifndef SURICATA_UTIL_LUAJIT_H
-#define SURICATA_UTIL_LUAJIT_H
-
-#ifdef HAVE_LUAJIT
-
-#include "util-lua.h"
-
-int LuajitSetupStatesPool(void);
-void LuajitFreeStatesPool(void);
-lua_State *LuajitGetState(void);
-void LuajitReturnState(lua_State *s);
-
-#endif /* HAVE_LUAJIT */
-
-#endif /* SURICATA_UTIL_LUAJIT_H */
index fe031b11526ae01c9d5440e4c2194e614a3cffe2..79d936c0ccdc16ae90eab8662fc449c2517eba88 100644 (file)
@@ -1792,15 +1792,6 @@ threading:
   # Generally, the per-thread stack-size should not exceed 8MB.
   #stack-size: 8mb
 
-# Luajit has a strange memory requirement, its 'states' need to be in the
-# first 2G of the process' memory.
-#
-# 'luajit.states' is used to control how many states are preallocated.
-# State use: per detect script: 1 per detect thread. Per output script: 1 per
-# script.
-luajit:
-  states: 128
-
 # Profiling settings. Only effective if Suricata has been built with
 # the --enable-profiling configure flag.
 #