38 static const char suricata_packet[] =
"suricata:packet";
44 static int LuaPacketGC(
lua_State *luastate)
56 static int LuaPacketPayload(
lua_State *luastate)
59 if (s == NULL || s->
p == NULL) {
67 static int LuaPacketPacket(
lua_State *luastate)
70 if (s == NULL || s->
p == NULL) {
78 static int LuaPacketPcapCnt(
lua_State *luastate)
81 if (s == NULL || s->
p == NULL) {
92 static int LuaPacketTimestringLegacy(
lua_State *luastate)
95 if (s == NULL || s->
p == NULL) {
101 lua_pushstring(luastate, timebuf);
105 static int LuaPacketTimestringIso8601(
lua_State *luastate)
108 if (s == NULL || s->
p == NULL) {
114 lua_pushstring(luastate, timebuf);
118 static int LuaPacketTimestamp(
lua_State *luastate)
121 if (s == NULL || s->
p == NULL) {
138 static int LuaPacketTuple(
lua_State *luastate)
141 if (s == NULL || s->
p == NULL) {
147 if (PacketIsIPv4(
p)) {
149 }
else if (PacketIsIPv6(
p)) {
152 lua_pushinteger(luastate, ipver);
156 char srcip[46] =
"", dstip[46] =
"";
157 if (PacketIsIPv4(
p)) {
160 }
else if (PacketIsIPv6(
p)) {
165 lua_pushstring(luastate, srcip);
166 lua_pushstring(luastate, dstip);
169 lua_pushinteger(luastate,
p->
proto);
170 if (
p->
proto == IPPROTO_TCP ||
p->
proto == IPPROTO_UDP) {
171 lua_pushinteger(luastate,
p->
sp);
172 lua_pushinteger(luastate,
p->
dp);
174 }
else if (
p->
proto == IPPROTO_ICMP ||
p->
proto == IPPROTO_ICMPV6) {
175 lua_pushinteger(luastate,
p->
icmp_s.type);
176 lua_pushinteger(luastate,
p->
icmp_s.code);
178 lua_pushinteger(luastate, 0);
179 lua_pushinteger(luastate, 0);
189 static int LuaPacketSport(
lua_State *luastate)
192 if (s == NULL || s->
p == NULL) {
201 lua_pushinteger(luastate,
p->
sp);
204 LUA_ERROR(
"sp only available for tcp, udp and sctp");
214 static int LuaPacketDport(
lua_State *luastate)
217 if (s == NULL || s->
p == NULL) {
226 lua_pushinteger(luastate,
p->
dp);
229 LUA_ERROR(
"dp only available for tcp, udp and sctp");
235 static int LuaPacketGet(
lua_State *luastate)
247 luaL_getmetatable(luastate, suricata_packet);
248 lua_setmetatable(luastate, -2);
252 static const luaL_Reg packetlib[] = {
254 {
"get", LuaPacketGet },
259 static const luaL_Reg packetlib_meta[] = {
261 {
"packet", LuaPacketPacket },
262 {
"payload", LuaPacketPayload },
263 {
"pcap_cnt", LuaPacketPcapCnt },
264 {
"timestring_legacy", LuaPacketTimestringLegacy },
265 {
"timestring_iso8601", LuaPacketTimestringIso8601 },
266 {
"timestamp", LuaPacketTimestamp },
267 {
"tuple", LuaPacketTuple },
268 {
"sp", LuaPacketSport },
269 {
"dp", LuaPacketDport },
270 {
"__gc", LuaPacketGC },
277 luaL_newmetatable(luastate, suricata_packet);
278 lua_pushvalue(luastate, -1);
279 lua_setfield(luastate, -2,
"__index");
280 luaL_setfuncs(luastate, packetlib_meta, 0);
282 luaL_newlib(luastate, packetlib);