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 __UTIL_LUA_H__
25 #define __UTIL_LUA_H__
26 
27 #ifndef HAVE_LUA
28 
29 /* If we don't have Lua, create a typedef for lua_State so the
30  * exported Lua functions don't fail the build. */
31 typedef void lua_State;
32 
33 #else
34 #include "threadvars.h"
35 #include "detect.h"
36 
37 typedef struct LuaStreamingBuffer_ {
38  const uint8_t *data;
39  uint32_t data_len;
40  uint8_t flags;
41 } LuaStreamingBuffer;
42 
43 lua_State *LuaGetState(void);
44 void LuaReturnState(lua_State *s);
45 
46 /* gets */
47 
48 /** \brief get tv pointer from the lua state */
49 ThreadVars *LuaStateGetThreadVars(lua_State *luastate);
50 
51 Packet *LuaStateGetPacket(lua_State *luastate);
52 void *LuaStateGetTX(lua_State *luastate);
53 uint64_t LuaStateGetTxId(lua_State *luastate);
54 
55 /** \brief get flow pointer from lua state
56  *
57  * \retval f flow pointer or NULL if it was not set
58  */
59 Flow *LuaStateGetFlow(lua_State *luastate);
60 
61 PacketAlert *LuaStateGetPacketAlert(lua_State *luastate);
62 
63 Signature *LuaStateGetSignature(lua_State *luastate);
64 
65 /** \brief get file pointer from the lua state */
66 File *LuaStateGetFile(lua_State *luastate);
67 
68 /** \brief get detect engine thread context pointer from the lua state */
69 DetectEngineThreadCtx *LuaStateGetDetCtx(lua_State *luastate);
70 
71 LuaStreamingBuffer *LuaStateGetStreamingBuffer(lua_State *luastate);
72 
73 int LuaStateGetDirection(lua_State *luastate);
74 
75 /* sets */
76 
77 void LuaStateSetPacket(lua_State *luastate, Packet *p);
78 void LuaStateSetTX(lua_State *luastate, void *tx, const uint64_t tx_id);
79 
80 /** \brief set a flow pointer in the lua state
81  *
82  * \param f flow pointer
83  */
84 void LuaStateSetFlow(lua_State *luastate, Flow *f);
85 
86 void LuaStateSetPacketAlert(lua_State *luastate, PacketAlert *pa);
87 
88 void LuaStateSetSignature(lua_State *luastate, const Signature *s);
89 
90 void LuaStateSetFile(lua_State *luastate, File *file);
91 
92 void LuaStateSetDetCtx(lua_State *luastate, DetectEngineThreadCtx *det_ctx);
93 
94 void LuaStateSetThreadVars(lua_State *luastate, ThreadVars *tv);
95 
96 void LuaStateSetStreamingBuffer(lua_State *luastate, LuaStreamingBuffer *b);
97 
98 void LuaStateSetDirection(lua_State *luastate, int direction);
99 
100 void LuaPrintStack(lua_State *state);
101 
102 int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len);
103 
104 int LuaPushInteger(lua_State *luastate, lua_Integer n);
105 
106 #endif /* HAVE_LUA */
107 
108 #endif /* __UTIL_LUA_H__ */
lua_State
void lua_State
Definition: util-lua.h:31
Flow_
Flow data structure.
Definition: flow.h:347
DetectEngineThreadCtx_
Definition: detect.h:1074
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
Packet_
Definition: decode.h:430
File_
Definition: util-file.h:79
flags
uint8_t flags
Definition: decode-gre.h:0
lua_State
void lua_State
Definition: suricata-common.h:495
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
threadvars.h
Signature_
Signature container.
Definition: detect.h:581
PacketAlert_
Definition: decode.h:263