38 static const char suricata_flow[] =
"suricata:flow";
66 if (s == NULL || s->
f == NULL) {
72 int64_t
id = (int64_t)FlowGetId(
f);
73 lua_pushinteger(luastate,
id);
86 static int LuaFlowAppLayerProto(
lua_State *luastate)
89 if (s == NULL || s->
f == NULL) {
109 static int LuaFlowHasAlerts(
lua_State *luastate)
111 struct LuaFlow *s = (
struct LuaFlow *)lua_touserdata(luastate, 1);
112 if (s == NULL || s->
f == NULL) {
128 static int LuaFlowStats(
lua_State *luastate)
130 struct LuaFlow *s = (
struct LuaFlow *)lua_touserdata(luastate, 1);
131 if (s == NULL || s->
f == NULL) {
151 static int LuaFlowTimestamps(
lua_State *luastate)
153 struct LuaFlow *s = (
struct LuaFlow *)lua_touserdata(luastate, 1);
154 if (s == NULL || s->
f == NULL) {
166 static int LuaFlowTimestringIso8601(
lua_State *luastate)
168 struct LuaFlow *s = (
struct LuaFlow *)lua_touserdata(luastate, 1);
169 if (s == NULL || s->
f == NULL) {
176 lua_pushstring(luastate, timebuf);
183 static int LuaFlowTimestringLegacy(
lua_State *luastate)
185 struct LuaFlow *s = (
struct LuaFlow *)lua_touserdata(luastate, 1);
186 if (s == NULL || s->
f == NULL) {
193 lua_pushstring(luastate, timebuf);
205 static int LuaFlowTuple(
lua_State *luastate)
207 struct LuaFlow *s = (
struct LuaFlow *)lua_touserdata(luastate, 1);
208 if (s == NULL || s->
f == NULL) {
218 lua_pushinteger(luastate, ipver);
222 char srcip[46] =
"", dstip[46] =
"";
224 PrintInet(AF_INET, (
const void *)&(
f->
src.addr_data32[0]), srcip,
sizeof(srcip));
225 PrintInet(AF_INET, (
const void *)&(
f->
dst.addr_data32[0]), dstip,
sizeof(dstip));
231 lua_pushstring(luastate, srcip);
232 lua_pushstring(luastate, dstip);
235 lua_pushinteger(luastate,
f->
proto);
236 if (
f->
proto == IPPROTO_TCP ||
f->
proto == IPPROTO_UDP) {
237 lua_pushinteger(luastate,
f->
sp);
238 lua_pushinteger(luastate,
f->
dp);
239 }
else if (
f->
proto == IPPROTO_ICMP ||
f->
proto == IPPROTO_ICMPV6) {
240 lua_pushinteger(luastate,
f->
icmp_s.type);
241 lua_pushinteger(luastate,
f->
icmp_s.code);
243 lua_pushinteger(luastate, 0);
244 lua_pushinteger(luastate, 0);
249 static int LuaFlowGet(
lua_State *luastate)
256 struct LuaFlow *s = (
struct LuaFlow *)lua_newuserdata(luastate,
sizeof(*s));
258 LUA_ERROR(
"failed to allocate userdata");
261 luaL_getmetatable(luastate, suricata_flow);
262 lua_setmetatable(luastate, -2);
266 static const luaL_Reg flowlib[] = {
268 {
"get", LuaFlowGet },
273 static const luaL_Reg flowlib_meta[] = {
276 {
"app_layer_proto", LuaFlowAppLayerProto },
277 {
"has_alerts", LuaFlowHasAlerts },
278 {
"stats", LuaFlowStats },
279 {
"timestamps", LuaFlowTimestamps },
280 {
"timestring_iso8601", LuaFlowTimestringIso8601 },
281 {
"timestring_legacy", LuaFlowTimestringLegacy },
282 {
"tuple", LuaFlowTuple },
283 {
"__gc", LuaFlowGC },
290 luaL_newmetatable(luastate, suricata_flow);
291 lua_pushvalue(luastate, -1);
292 lua_setfield(luastate, -2,
"__index");
293 luaL_setfuncs(luastate, flowlib_meta, 0);
295 luaL_newlib(luastate, flowlib);