]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
lua: convert dnp3 to suricata.dnp3 lib
authorJason Ish <jason.ish@oisf.net>
Thu, 27 Mar 2025 16:46:49 +0000 (10:46 -0600)
committerJason Ish <jason.ish@oisf.net>
Thu, 27 Mar 2025 16:56:20 +0000 (10:56 -0600)
This is an initial 1:1 conversion which is rather simple, as DNP3 only
had one function which converted the whole transaction to a DNP3
table.

Ticket: #7601

src/detect-lua-extensions.c
src/util-lua-builtins.c
src/util-lua-dnp3.c
src/util-lua-dnp3.h

index 045957e4c39266b5ed5603bd6acc7e0f2cde12a8..eb0de09c52caa52e00b497d8dfbceb7e311cf2dc 100644 (file)
@@ -556,6 +556,5 @@ int LuaRegisterExtensions(lua_State *lua_state)
     LuaRegisterSshFunctions(lua_state);
     LuaRegisterHasshFunctions(lua_state);
     LuaRegisterSmtpFunctions(lua_state);
-    LuaRegisterDNP3Functions(lua_state);
     return 0;
 }
index 7c5bb08e61f52972cab1a08f61efd9b631077597..d03e56d22422ecf52f511c1f79292b6b77ec0e5d 100644 (file)
@@ -19,6 +19,7 @@
 #include "util-lua-builtins.h"
 #include "util-lua-base64lib.h"
 #include "util-lua-dataset.h"
+#include "util-lua-dnp3.h"
 #include "util-lua-dns.h"
 #include "util-lua-hashlib.h"
 #include "util-lua-packetlib.h"
@@ -28,6 +29,7 @@
 static const luaL_Reg builtins[] = {
     { "suricata.base64", SCLuaLoadBase64Lib },
     { "suricata.dataset", LuaLoadDatasetLib },
+    { "suricata.dnp3", SCLuaLoadDnp3Lib },
     { "suricata.dns", SCLuaLoadDnsLib },
     { "suricata.hashlib", SCLuaLoadHashlib },
     { "suricata.packet", LuaLoadPacketLib },
index 571a1d42cd0d03c0fd2919f7f1a162d7587e1ece..2efc50b5b66a97ece0d2ebea84116ec6f5d3100e 100644 (file)
@@ -188,10 +188,15 @@ static int DNP3GetTx(lua_State *luastate)
     return 1;
 }
 
-int LuaRegisterDNP3Functions(lua_State *luastate)
+static const struct luaL_Reg dnp3lib[] = {
+    // clang-format off
+    { "get_tx", DNP3GetTx, },
+    { NULL, NULL, }
+    // clang-format on
+};
+
+int SCLuaLoadDnp3Lib(lua_State *L)
 {
-    lua_pushcfunction(luastate, DNP3GetTx);
-    lua_setglobal(luastate, "DNP3GetTx");
-
-    return 0;
+    luaL_newlib(L, dnp3lib);
+    return 1;
 }
index a594fbfbe8c1f0b92a09b9115f1950adb831f53d..b13466c1dbb573a92d8d8543a6bedd08ca4bb351 100644 (file)
@@ -18,6 +18,6 @@
 #ifndef SURICATA_UTIL_LUA_DNP3_H
 #define SURICATA_UTIL_LUA_DNP3_H
 
-int LuaRegisterDNP3Functions(lua_State *);
+int SCLuaLoadDnp3Lib(lua_State *L);
 
 #endif /* !SURICATA_UTIL_LUA_DNP3_H */