36 static const char suricata_packet[] =
"suricata:packet";
44 static int LuaPacketPayload(
lua_State *luastate)
56 static int LuaPacketPacket(
lua_State *luastate)
68 static int LuaPacketPcapCnt(
lua_State *luastate)
83 static int LuaPacketTimestringLegacy(
lua_State *luastate)
93 lua_pushstring(luastate, timebuf);
97 static int LuaPacketTimestringIso8601(
lua_State *luastate)
107 lua_pushstring(luastate, timebuf);
111 static int LuaPacketTimestamp(
lua_State *luastate)
132 static int LuaPacketTuple(
lua_State *luastate)
141 if (PacketIsIPv4(
p)) {
143 }
else if (PacketIsIPv6(
p)) {
146 lua_pushinteger(luastate, ipver);
150 char srcip[46] =
"", dstip[46] =
"";
151 if (PacketIsIPv4(
p)) {
154 }
else if (PacketIsIPv6(
p)) {
159 lua_pushstring(luastate, srcip);
160 lua_pushstring(luastate, dstip);
163 lua_pushinteger(luastate,
p->
proto);
164 if (
p->
proto == IPPROTO_TCP ||
p->
proto == IPPROTO_UDP) {
165 lua_pushinteger(luastate,
p->
sp);
166 lua_pushinteger(luastate,
p->
dp);
168 }
else if (
p->
proto == IPPROTO_ICMP ||
p->
proto == IPPROTO_ICMPV6) {
169 lua_pushinteger(luastate,
p->
icmp_s.type);
170 lua_pushinteger(luastate,
p->
icmp_s.code);
172 lua_pushinteger(luastate, 0);
173 lua_pushinteger(luastate, 0);
183 static int LuaPacketSport(
lua_State *luastate)
195 lua_pushinteger(luastate,
p->
sp);
198 LUA_ERROR(
"sp only available for tcp, udp and sctp");
208 static int LuaPacketDport(
lua_State *luastate)
220 lua_pushinteger(luastate,
p->
dp);
223 LUA_ERROR(
"dp only available for tcp, udp and sctp");
229 static int LuaPacketGet(
lua_State *luastate)
240 luaL_getmetatable(luastate, suricata_packet);
241 lua_setmetatable(luastate, -2);
245 static const luaL_Reg packetlib[] = {
247 {
"get", LuaPacketGet },
252 static const luaL_Reg packetlib_meta[] = {
254 {
"packet", LuaPacketPacket },
255 {
"payload", LuaPacketPayload },
256 {
"pcap_cnt", LuaPacketPcapCnt },
257 {
"timestring_legacy", LuaPacketTimestringLegacy },
258 {
"timestring_iso8601", LuaPacketTimestringIso8601 },
259 {
"timestamp", LuaPacketTimestamp },
260 {
"tuple", LuaPacketTuple },
261 {
"sp", LuaPacketSport },
262 {
"dp", LuaPacketDport },
269 luaL_newmetatable(luastate, suricata_packet);
270 lua_pushvalue(luastate, -1);
271 lua_setfield(luastate, -2,
"__index");
272 luaL_setfuncs(luastate, packetlib_meta, 0);
274 luaL_newlib(luastate, packetlib);