30 static const char suricata_flowint_mt[] =
"suricata:flowint:mt";
46 static int LuaFlowintRegister(
lua_State *L)
50 return luaL_error(L,
"flowint API not available in this context");
53 return luaL_error(L,
"flowint.register() must be called from init()");
55 const char *
name = luaL_checkstring(L, 1);
59 return luaL_error(L,
"too many flowints registered");
62 if (flowvar_id == NULL) {
63 return luaL_error(L,
"failed to allocate flowint");
66 if (*flowvar_id == 0) {
67 return luaL_error(L,
"failed to register flowint");
71 luaL_getmetatable(L, suricata_flowint_mt);
72 lua_setmetatable(L, -2);
79 const char *
name = luaL_checkstring(L, 1);
81 if (flowvar_id == NULL) {
82 return luaL_error(L,
"failed to allocate flowint");
85 if (*flowvar_id == 0) {
86 return luaL_error(L,
"flowvar does not exist");
89 luaL_getmetatable(L, suricata_flowint_mt);
90 lua_setmetatable(L, -2);
113 const lua_Integer value = luaL_checkinteger(L, 2);
117 return luaL_error(L,
"no flow");
124 const int64_t v = (int64_t)value;
125 if (v < 0 || (uint64_t)v > (uint64_t)UINT32_MAX) {
126 return luaL_error(L,
"value out of range: must be 0..4294967295");
141 return luaL_error(L,
"no flow");
150 if (value < UINT32_MAX) {
156 lua_pushnumber(L, (lua_Number)value);
166 return luaL_error(L,
"no flow");
181 lua_pushnumber(L, (lua_Number)value);
186 static const luaL_Reg flowvarlib[] = {
188 {
"register", LuaFlowintRegister, },
189 {
"get", LuaFlowintGet },
194 static const luaL_Reg flowvarmt[] = {
196 {
"value", LuaFlowintValue, },
197 {
"set", LuaFlowintSet, },
198 {
"incr", LuaFlowintIncr, },
199 {
"decr", LuaFlowintDecr, },
206 luaL_newmetatable(L, suricata_flowint_mt);
207 lua_pushvalue(L, -1);
208 lua_setfield(L, -2,
"__index");
209 luaL_setfuncs(L, flowvarmt, 0);
211 luaL_newlib(L, flowvarlib);