suricata
detect-lua-extensions.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-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  * Functions to expose to the lua scripts.
24  */
25 
26 #include "suricata-common.h"
27 
28 #include "decode.h"
29 #include "detect.h"
30 
31 #include "flow.h"
32 
33 #include "util-debug.h"
34 
35 #include "detect-lua.h"
36 
37 #include "rust.h"
38 #include "app-layer-parser.h"
39 
40 #include "util-lua.h"
41 #include "util-lua-common.h"
42 #include "detect-lua-extensions.h"
43 
44 /* Lua registry key for DetectLuaData. */
45 const char luaext_key_ld[] = "suricata:luadata";
46 
48  DetectEngineThreadCtx *det_ctx, Flow *f, Packet *p, const Signature *s, uint8_t flags)
49 {
50  SCLogDebug("det_ctx %p, f %p", det_ctx, f);
51 
52  LuaStateSetThreadVars(lua_state, det_ctx->tv);
53  LuaStateSetSignature(lua_state, s);
54  LuaStateSetFlow(lua_state, f);
55  LuaStateSetDetCtx(lua_state, det_ctx);
56 
57  void *txptr = NULL;
58  if (det_ctx->tx_id_set && f && f->alstate)
59  txptr = AppLayerParserGetTx(f->proto, f->alproto, f->alstate, det_ctx->tx_id);
60  /* write both entries unconditionally: a failed or not-attempted
61  * lookup clears the previous transaction, and the packet entry dies
62  * with its packet, so the state can never wrap a stale pointer */
63  LuaStateSetTX(lua_state, txptr, txptr ? det_ctx->tx_id : 0);
64  LuaStateSetPacket(lua_state, p);
65 
66  LuaStateSetDirection(lua_state, (flags & STREAM_TOSERVER));
67 }
LuaStateSetTX
void LuaStateSetTX(lua_State *luastate, void *txptr, const uint64_t tx_id)
Definition: util-lua.c:248
LuaStateSetPacket
void LuaStateSetPacket(lua_State *luastate, Packet *p)
Definition: util-lua.c:228
DetectLuaData
Definition: detect-lua.h:44
LuaStateSetThreadVars
void LuaStateSetThreadVars(lua_State *luastate, ThreadVars *tv)
Definition: util-lua.c:193
util-lua-common.h
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
Flow_::proto
uint8_t proto
Definition: flow.h:382
util-lua.h
DetectEngineThreadCtx_::tx_id
uint64_t tx_id
Definition: detect.h:1376
Flow_
Flow data structure.
Definition: flow.h:360
detect-lua.h
rust.h
p
Packet * p
Definition: fuzz_dataset.c:30
LuaStateSetFlow
void LuaStateSetFlow(lua_State *luastate, Flow *f)
set a flow pointer in the lua state
Definition: util-lua.c:267
lua_State
struct lua_State lua_State
Definition: suricata-common.h:527
decode.h
util-debug.h
DetectEngineThreadCtx_
Definition: detect.h:1295
detect.h
app-layer-parser.h
LuaStateSetDetCtx
void LuaStateSetDetCtx(lua_State *luastate, DetectEngineThreadCtx *det_ctx)
Definition: util-lua.c:313
Packet_
Definition: decode.h:528
LuaExtensionsMatchSetup
void LuaExtensionsMatchSetup(lua_State *lua_state, DetectLuaData *ld, DetectEngineThreadCtx *det_ctx, Flow *f, Packet *p, const Signature *s, uint8_t flags)
Definition: detect-lua-extensions.c:47
AppLayerParserGetTx
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
Definition: app-layer-parser.c:1219
flags
uint8_t flags
Definition: decode-gre.h:0
detect-lua-extensions.h
suricata-common.h
luaext_key_ld
const char luaext_key_ld[]
Definition: detect-lua-extensions.c:45
DetectEngineThreadCtx_::tv
ThreadVars * tv
Definition: detect.h:1303
LuaStateSetDirection
void LuaStateSetDirection(lua_State *luastate, int direction)
Definition: util-lua.c:339
Flow_::alstate
void * alstate
Definition: flow.h:486
Signature_
Signature container.
Definition: detect.h:663
DetectEngineThreadCtx_::tx_id_set
bool tx_id_set
Definition: detect.h:1338
flow.h
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:457
LuaStateSetSignature
void LuaStateSetSignature(lua_State *luastate, const Signature *s)
Definition: util-lua.c:290
f
Flow f
Definition: fuzz_dataset.c:32