suricata
util-lua.h
Go to the documentation of this file.
1 /* Copyright (C) 2014-2022 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  */
23 
24 #ifndef SURICATA_UTIL_LUA_H
25 #define SURICATA_UTIL_LUA_H
26 
27 #include "lua.h"
28 #include "lualib.h"
29 #include "lauxlib.h"
30 
31 #include "threadvars.h"
32 #include "detect.h"
33 
34 /* see detect-lua.h */
35 typedef struct DetectLuaData DetectLuaData;
36 
37 lua_State *LuaGetState(void);
38 void LuaReturnState(lua_State *s);
39 
40 /* gets */
41 
42 /** \brief get tv pointer from the lua state */
44 
46 void *LuaStateGetTX(lua_State *luastate);
47 uint64_t LuaStateGetTxId(lua_State *luastate);
48 
49 /** \brief get flow pointer from lua state
50  *
51  * \retval f flow pointer or NULL if it was not set
52  */
53 Flow *LuaStateGetFlow(lua_State *luastate);
54 
56 
58 
59 /** \brief get file pointer from the lua state */
60 File *LuaStateGetFile(lua_State *luastate);
61 
62 /** \brief get detect engine thread context pointer from the lua state */
64 
65 /** \brief get the per-rule DetectLuaData, NULL when the state has none
66  * (output/transform states) */
68 
70 
71 int LuaStateGetDirection(lua_State *luastate);
72 
73 /* \brief get a string argument from the stack, NULL when absent or empty */
74 const char *LuaGetStringArgument(lua_State *luastate, int idx);
75 
76 /* sets */
77 
78 void LuaStateSetPacket(lua_State *luastate, Packet *p);
79 void LuaStateSetTX(lua_State *luastate, void *tx, const uint64_t tx_id);
80 
81 /** \brief set a flow pointer in the lua state
82  *
83  * \param f flow pointer
84  */
85 void LuaStateSetFlow(lua_State *luastate, Flow *f);
86 
87 void LuaStateSetPacketAlert(lua_State *luastate, PacketAlert *pa);
88 
89 void LuaStateSetSignature(lua_State *luastate, const Signature *s);
90 
91 void LuaStateSetFile(lua_State *luastate, File *file);
92 
93 void LuaStateSetDetCtx(lua_State *luastate, DetectEngineThreadCtx *det_ctx);
94 
96 
97 /** \brief publish the state's invocation counter (once, at state init) */
98 void LuaStateSetInvocationGen(lua_State *luastate, uint64_t *gen);
99 /** \brief current invocation generation; 0 when the state has none */
100 uint64_t LuaStateGetInvocationGen(lua_State *luastate);
101 
102 void LuaStateSetDirection(lua_State *luastate, int direction);
103 
104 void LuaPrintStack(lua_State *state);
105 
106 int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len);
107 
108 int LuaPushInteger(lua_State *luastate, lua_Integer n);
109 
110 #endif /* SURICATA_UTIL_LUA_H */
LuaStateSetDirection
void LuaStateSetDirection(lua_State *luastate, int direction)
Definition: util-lua.c:339
DetectLuaData
Definition: detect-lua.h:44
LuaGetStringArgument
const char * LuaGetStringArgument(lua_State *luastate, int idx)
Definition: util-lua-common.c:225
LuaStateGetDirection
int LuaStateGetDirection(lua_State *luastate)
get packet pointer from the lua state
Definition: util-lua.c:330
LuaStateSetDetCtx
void LuaStateSetDetCtx(lua_State *luastate, DetectEngineThreadCtx *det_ctx)
Definition: util-lua.c:313
Flow_
Flow data structure.
Definition: flow.h:360
LuaStateSetSignature
void LuaStateSetSignature(lua_State *luastate, const Signature *s)
Definition: util-lua.c:290
LuaStateGetDetectLuaData
DetectLuaData * LuaStateGetDetectLuaData(lua_State *luastate)
get the per-rule DetectLuaData, NULL when the state has none (output/transform states)
Definition: util-lua.c:319
LuaStateSetFile
void LuaStateSetFile(lua_State *luastate, File *file)
Definition: util-lua.c:301
LuaReturnState
void LuaReturnState(lua_State *s)
Definition: util-lua.c:63
LuaStateGetFlow
Flow * LuaStateGetFlow(lua_State *luastate)
get flow pointer from lua state
Definition: util-lua.c:260
LuaStateSetPacket
void LuaStateSetPacket(lua_State *luastate, Packet *p)
Definition: util-lua.c:228
p
Packet * p
Definition: fuzz_dataset.c:30
LuaStateGetPacketAlert
PacketAlert * LuaStateGetPacketAlert(lua_State *luastate)
get packet alert pointer from the lua state
Definition: util-lua.c:274
LuaStateSetInvocationGen
void LuaStateSetInvocationGen(lua_State *luastate, uint64_t *gen)
publish the state's invocation counter (once, at state init)
Definition: util-lua.c:210
lua_State
struct lua_State lua_State
Definition: suricata-common.h:527
LuaStateGetFile
File * LuaStateGetFile(lua_State *luastate)
get file pointer from the lua state
Definition: util-lua.c:296
LuaStateSetTX
void LuaStateSetTX(lua_State *luastate, void *tx, const uint64_t tx_id)
Definition: util-lua.c:248
LuaPushStringBuffer
int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len)
Definition: util-lua.c:380
LuaStateGetTX
void * LuaStateGetTX(lua_State *luastate)
get tx pointer from the lua state
Definition: util-lua.c:234
DetectEngineThreadCtx_
Definition: detect.h:1295
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
Packet_
Definition: decode.h:528
LuaStateGetPacket
Packet * LuaStateGetPacket(lua_State *luastate)
get packet pointer from the lua state
Definition: util-lua.c:223
LuaGetState
lua_State * LuaGetState(void)
Definition: util-lua.c:56
LuaPushInteger
int LuaPushInteger(lua_State *luastate, lua_Integer n)
Definition: util-lua.c:393
LuaPrintStack
void LuaPrintStack(lua_State *state)
dump stack from lua state to screen
Definition: util-lua.c:347
LuaStateGetThreadVars
ThreadVars * LuaStateGetThreadVars(lua_State *luastate)
get tv pointer from the lua state
Definition: util-lua.c:188
File_
Definition: util-file.h:146
LuaStateGetInvocationGen
uint64_t LuaStateGetInvocationGen(lua_State *luastate)
current invocation generation; 0 when the state has none
Definition: util-lua.c:216
LuaStateGetSignature
Signature * LuaStateGetSignature(lua_State *luastate)
get signature pointer from the lua state
Definition: util-lua.c:285
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:34
threadvars.h
Signature_
Signature container.
Definition: detect.h:663
LuaStateSetThreadVars
void LuaStateSetThreadVars(lua_State *luastate, ThreadVars *tv)
Definition: util-lua.c:193
LuaStateSetFlow
void LuaStateSetFlow(lua_State *luastate, Flow *f)
set a flow pointer in the lua state
Definition: util-lua.c:267
PacketAlert_
Definition: decode.h:266
LuaStateGetDetCtx
DetectEngineThreadCtx * LuaStateGetDetCtx(lua_State *luastate)
get detect engine thread context pointer from the lua state
Definition: util-lua.c:307
LuaStateGetTxId
uint64_t LuaStateGetTxId(lua_State *luastate)
get tx id from the lua state
Definition: util-lua.c:240
LuaStateSetPacketAlert
void LuaStateSetPacketAlert(lua_State *luastate, PacketAlert *pa)
Definition: util-lua.c:279
LuaStateSetDetectLuaData
void LuaStateSetDetectLuaData(lua_State *luastate, DetectLuaData *ld)
Definition: util-lua.c:324
f
Flow f
Definition: fuzz_dataset.c:32