From: Victor Julien Date: Tue, 5 Nov 2013 20:45:08 +0000 (+0100) Subject: luajit: pass calling rule's sid,gid,rev to script as SCRuleSid, SCRuleGid, SCRuleRev. X-Git-Tag: suricata-2.0beta2~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae69a4a024aa666e4051c8ea4c73cd363e97a03d;p=thirdparty%2Fsuricata.git luajit: pass calling rule's sid,gid,rev to script as SCRuleSid, SCRuleGid, SCRuleRev. --- diff --git a/src/detect-luajit.c b/src/detect-luajit.c index 71ee59e982..a88c550bc6 100644 --- a/src/detect-luajit.c +++ b/src/detect-luajit.c @@ -499,6 +499,13 @@ static void *DetectLuajitThreadInit(void *data) { LuajitRegisterExtensions(t->luastate); + lua_pushinteger(t->luastate, (lua_Integer)(luajit->sid)); + lua_setglobal(t->luastate, "SCRuleSid"); + lua_pushinteger(t->luastate, (lua_Integer)(luajit->rev)); + lua_setglobal(t->luastate, "SCRuleRev"); + lua_pushinteger(t->luastate, (lua_Integer)(luajit->gid)); + lua_setglobal(t->luastate, "SCRuleGid"); + /* hackish, needed to allow unittests to pass buffers as scripts instead of files */ #ifdef UNITTESTS if (ut_script != NULL) { @@ -869,6 +876,26 @@ error: return -1; } +/** \brief post-sig parse function to set the sid,rev,gid into the + * ctx, as this isn't available yet during parsing. + */ +void DetectLuajitPostSetup(Signature *s) { + int i; + SigMatch *sm; + + for (i = 0; i < DETECT_SM_LIST_MAX; i++) { + for (sm = s->sm_lists[i]; sm != NULL; sm = sm->next) { + if (sm->type != DETECT_LUAJIT) + continue; + + DetectLuajitData *ld = sm->ctx; + ld->sid = s->id; + ld->rev = s->rev; + ld->gid = s->gid; + } + } +} + /** * \brief this function will free memory associated with DetectLuajitData * diff --git a/src/detect-luajit.h b/src/detect-luajit.h index 6d23452a09..00ce650608 100644 --- a/src/detect-luajit.h +++ b/src/detect-luajit.h @@ -50,6 +50,9 @@ typedef struct DetectLuajitData { uint16_t flowints; uint16_t flowvar[DETECT_LUAJIT_MAX_FLOWVARS]; uint16_t flowvars; + uint32_t sid; + uint32_t rev; + uint32_t gid; } DetectLuajitData; #endif @@ -60,5 +63,6 @@ int DetectLuajitMatchBuffer(DetectEngineThreadCtx *det_ctx, Signature *s, SigMat Flow *f, int need_flow_lock); int DetectLuajitSetupStatesPool(int num, int reloads); +void DetectLuajitPostSetup(Signature *s); #endif /* __DETECT_FILELUAJIT_H__ */ diff --git a/src/detect-parse.c b/src/detect-parse.c index 887fb85aa9..25a0d0455e 100644 --- a/src/detect-parse.c +++ b/src/detect-parse.c @@ -41,6 +41,7 @@ #include "detect-flow.h" #include "detect-app-layer-protocol.h" #include "detect-engine-apt-event.h" +#include "detect-luajit.h" #include "pkt-var.h" #include "host.h" @@ -1331,6 +1332,10 @@ int SigValidate(DetectEngineCtx *de_ctx, Signature *s) { } } +#ifdef HAVE_LUAJIT + DetectLuajitPostSetup(s); +#endif + #ifdef DEBUG int i; for (i = 0; i < DETECT_SM_LIST_MAX; i++) {