38 static const char suricata_flow[] =
"suricata:flow";
64 if (s == NULL || s->
f == NULL) {
70 int64_t
id = FlowGetId(
f);
71 lua_pushinteger(luastate,
id);
84 static int LuaFlowAppLayerProto(
lua_State *luastate)
87 if (s == NULL || s->
f == NULL) {
107 static int LuaFlowHasAlerts(
lua_State *luastate)
109 struct LuaFlow *s = (
struct LuaFlow *)lua_touserdata(luastate, 1);
110 if (s == NULL || s->
f == NULL) {
126 static int LuaFlowStats(
lua_State *luastate)
128 struct LuaFlow *s = (
struct LuaFlow *)lua_touserdata(luastate, 1);
129 if (s == NULL || s->
f == NULL) {
149 static int LuaFlowTimestamps(
lua_State *luastate)
151 struct LuaFlow *s = (
struct LuaFlow *)lua_touserdata(luastate, 1);
152 if (s == NULL || s->
f == NULL) {
164 static int LuaFlowTimestringIso8601(
lua_State *luastate)
166 struct LuaFlow *s = (
struct LuaFlow *)lua_touserdata(luastate, 1);
167 if (s == NULL || s->
f == NULL) {
174 lua_pushstring(luastate, timebuf);
181 static int LuaFlowTimestringLegacy(
lua_State *luastate)
183 struct LuaFlow *s = (
struct LuaFlow *)lua_touserdata(luastate, 1);
184 if (s == NULL || s->
f == NULL) {
191 lua_pushstring(luastate, timebuf);
203 static int LuaFlowTuple(
lua_State *luastate)
205 struct LuaFlow *s = (
struct LuaFlow *)lua_touserdata(luastate, 1);
206 if (s == NULL || s->
f == NULL) {
216 lua_pushinteger(luastate, ipver);
220 char srcip[46] =
"", dstip[46] =
"";
222 PrintInet(AF_INET, (
const void *)&(
f->
src.addr_data32[0]), srcip,
sizeof(srcip));
223 PrintInet(AF_INET, (
const void *)&(
f->
dst.addr_data32[0]), dstip,
sizeof(dstip));
229 lua_pushstring(luastate, srcip);
230 lua_pushstring(luastate, dstip);
233 lua_pushinteger(luastate,
f->
proto);
234 if (
f->
proto == IPPROTO_TCP ||
f->
proto == IPPROTO_UDP) {
235 lua_pushinteger(luastate,
f->
sp);
236 lua_pushinteger(luastate,
f->
dp);
237 }
else if (
f->
proto == IPPROTO_ICMP ||
f->
proto == IPPROTO_ICMPV6) {
238 lua_pushinteger(luastate,
f->
icmp_s.type);
239 lua_pushinteger(luastate,
f->
icmp_s.code);
241 lua_pushinteger(luastate, 0);
242 lua_pushinteger(luastate, 0);
247 static int LuaFlowGet(
lua_State *luastate)
254 struct LuaFlow *s = (
struct LuaFlow *)lua_newuserdata(luastate,
sizeof(*s));
256 LUA_ERROR(
"failed to allocate userdata");
259 luaL_getmetatable(luastate, suricata_flow);
260 lua_setmetatable(luastate, -2);
264 static const luaL_Reg flowlib[] = {
266 {
"get", LuaFlowGet },
271 static const luaL_Reg flowlib_meta[] = {
274 {
"app_layer_proto", LuaFlowAppLayerProto },
275 {
"has_alerts", LuaFlowHasAlerts },
276 {
"stats", LuaFlowStats },
277 {
"timestamps", LuaFlowTimestamps },
278 {
"timestring_iso8601", LuaFlowTimestringIso8601 },
279 {
"timestring_legacy", LuaFlowTimestringLegacy },
280 {
"tuple", LuaFlowTuple },
281 {
"__gc", LuaFlowGC },
288 luaL_newmetatable(luastate, suricata_flow);
289 lua_pushvalue(luastate, -1);
290 lua_setfield(luastate, -2,
"__index");
291 luaL_setfuncs(luastate, flowlib_meta, 0);
293 luaL_newlib(luastate, flowlib);