36 static const char suricata_flow[] =
"suricata:flow";
59 int64_t
id = (int64_t)FlowGetId(
f);
60 lua_pushinteger(luastate,
id);
67 lua_pushstring(luastate, s ? s :
"unknown");
79 static int LuaFlowAppLayerProto(
lua_State *luastate)
87 PushAlprotoString(luastate,
f->
alproto);
102 static int LuaFlowHasAlerts(
lua_State *luastate)
120 static int LuaFlowStats(
lua_State *luastate)
142 static int LuaFlowTimestamps(
lua_State *luastate)
156 static int LuaFlowTimestringIso8601(
lua_State *luastate)
165 lua_pushstring(luastate, timebuf);
172 static int LuaFlowTimestringLegacy(
lua_State *luastate)
181 lua_pushstring(luastate, timebuf);
193 static int LuaFlowTuple(
lua_State *luastate)
206 lua_pushinteger(luastate, ipver);
210 char srcip[46] =
"", dstip[46] =
"";
212 PrintInet(AF_INET, (
const void *)&(
f->
src.addr_data32[0]), srcip,
sizeof(srcip));
213 PrintInet(AF_INET, (
const void *)&(
f->
dst.addr_data32[0]), dstip,
sizeof(dstip));
219 lua_pushstring(luastate, srcip);
220 lua_pushstring(luastate, dstip);
223 lua_pushinteger(luastate,
f->
proto);
224 if (
f->
proto == IPPROTO_TCP ||
f->
proto == IPPROTO_UDP) {
225 lua_pushinteger(luastate,
f->
sp);
226 lua_pushinteger(luastate,
f->
dp);
227 }
else if (
f->
proto == IPPROTO_ICMP ||
f->
proto == IPPROTO_ICMPV6) {
228 lua_pushinteger(luastate,
f->
icmp_s.type);
229 lua_pushinteger(luastate,
f->
icmp_s.code);
231 lua_pushinteger(luastate, 0);
232 lua_pushinteger(luastate, 0);
237 static int LuaFlowGet(
lua_State *luastate)
246 LUA_ERROR(
"failed to allocate userdata");
248 luaL_getmetatable(luastate, suricata_flow);
249 lua_setmetatable(luastate, -2);
253 static const luaL_Reg flowlib[] = {
255 {
"get", LuaFlowGet },
260 static const luaL_Reg flowlib_meta[] = {
263 {
"app_layer_proto", LuaFlowAppLayerProto },
264 {
"has_alerts", LuaFlowHasAlerts },
265 {
"stats", LuaFlowStats },
266 {
"timestamps", LuaFlowTimestamps },
267 {
"timestring_iso8601", LuaFlowTimestringIso8601 },
268 {
"timestring_legacy", LuaFlowTimestringLegacy },
269 {
"tuple", LuaFlowTuple },
276 luaL_newmetatable(luastate, suricata_flow);
277 lua_pushvalue(luastate, -1);
278 lua_setfield(luastate, -2,
"__index");
279 luaL_setfuncs(luastate, flowlib_meta, 0);
281 luaL_newlib(luastate, flowlib);