30static const char suricata_flowint_mt[] =
"suricata:flowint:mt";
36 lua_gettable(luastate, LUA_REGISTRYINDEX);
37 ld = lua_touserdata(luastate, -1);
50static int LuaFlowintRegister(
lua_State *L)
53 const char *
name = luaL_checkstring(L, 1);
54 uint32_t *flowvar_id = lua_newuserdata(L,
sizeof(*flowvar_id));
56 if (*flowvar_id == 0) {
57 return luaL_error(L,
"failed to register flowvar");
61 luaL_getmetatable(L, suricata_flowint_mt);
62 lua_setmetatable(L, -2);
69 const char *
name = luaL_checkstring(L, 1);
70 uint32_t *flowvar_id = lua_newuserdata(L,
sizeof(*flowvar_id));
72 if (*flowvar_id == 0) {
73 return luaL_error(L,
"flowvar does not exist");
76 luaL_getmetatable(L, suricata_flowint_mt);
77 lua_setmetatable(L, -2);
84 uint32_t *flowvar_id = luaL_checkudata(L, 1, suricata_flowint_mt);
100 const int value = (int)luaL_checkinteger(L, 2);
101 uint32_t *flowvar_id = luaL_checkudata(L, 1, suricata_flowint_mt);
104 return luaL_error(L,
"no flow");
114 uint32_t *flowvar_id = luaL_checkudata(L, 1, suricata_flowint_mt);
117 return luaL_error(L,
"no flow");
126 if (value < UINT32_MAX) {
132 lua_pushnumber(L, (lua_Number)value);
139 uint32_t *flowvar_id = luaL_checkudata(L, 1, suricata_flowint_mt);
142 return luaL_error(L,
"no flow");
157 lua_pushnumber(L, (lua_Number)value);
162static const luaL_Reg flowvarlib[] = {
164 {
"register", LuaFlowintRegister, },
165 {
"get", LuaFlowintGet },
170static const luaL_Reg flowvarmt[] = {
172 {
"value", LuaFlowintValue, },
173 {
"set", LuaFlowintSet, },
174 {
"incr", LuaFlowintIncr, },
175 {
"decr", LuaFlowintDecr, },
182 luaL_newmetatable(L, suricata_flowint_mt);
183 lua_pushvalue(L, -1);
184 lua_setfield(L, -2,
"__index");
185 luaL_setfuncs(L, flowvarmt, 0);
187 luaL_newlib(L, flowvarlib);
const char luaext_key_ld[]
FlowVar * FlowVarGet(Flow *f, uint32_t idx)
get the flowvar with index 'idx' from the flow
void FlowVarAddInt(Flow *f, uint32_t idx, uint32_t value)
uint32_t flowint[DETECT_LUA_MAX_FLOWINTS]
union FlowVar_::@124 data
struct lua_State lua_State
int LuaCallbackError(lua_State *luastate, const char *msg)
int LuaLoadFlowintLib(lua_State *L)
Flow * LuaStateGetFlow(lua_State *luastate)
get flow pointer from lua state
uint32_t VarNameStoreRegister(const char *name, const enum VarTypes type)
uint32_t VarNameStoreLookupByName(const char *name, const enum VarTypes type)
find name for id+type at packet time. As the active store won't be modified, we don't need locks.