38 static const char suricata_packet[] =
"suricata:packet";
44 static int LuaPacketGC(
lua_State *luastate)
54 static int LuaPacketPayload(
lua_State *luastate)
57 if (s == NULL || s->
p == NULL) {
65 static int LuaPacketPacket(
lua_State *luastate)
68 if (s == NULL || s->
p == NULL) {
76 static int LuaPacketPcapCnt(
lua_State *luastate)
79 if (s == NULL || s->
p == NULL) {
83 lua_pushinteger(luastate, s->
p->
pcap_cnt);
90 static int LuaPacketTimestringLegacy(
lua_State *luastate)
93 if (s == NULL || s->
p == NULL) {
99 lua_pushstring(luastate, timebuf);
103 static int LuaPacketTimestringIso8601(
lua_State *luastate)
106 if (s == NULL || s->
p == NULL) {
112 lua_pushstring(luastate, timebuf);
116 static int LuaPacketTimestamp(
lua_State *luastate)
119 if (s == NULL || s->
p == NULL) {
136 static int LuaPacketTuple(
lua_State *luastate)
139 if (s == NULL || s->
p == NULL) {
145 if (PacketIsIPv4(
p)) {
147 }
else if (PacketIsIPv6(
p)) {
150 lua_pushinteger(luastate, ipver);
154 char srcip[46] =
"", dstip[46] =
"";
155 if (PacketIsIPv4(
p)) {
158 }
else if (PacketIsIPv6(
p)) {
163 lua_pushstring(luastate, srcip);
164 lua_pushstring(luastate, dstip);
167 lua_pushinteger(luastate,
p->
proto);
168 if (
p->
proto == IPPROTO_TCP ||
p->
proto == IPPROTO_UDP) {
169 lua_pushinteger(luastate,
p->
sp);
170 lua_pushinteger(luastate,
p->
dp);
172 }
else if (
p->
proto == IPPROTO_ICMP ||
p->
proto == IPPROTO_ICMPV6) {
173 lua_pushinteger(luastate,
p->
icmp_s.type);
174 lua_pushinteger(luastate,
p->
icmp_s.code);
176 lua_pushinteger(luastate, 0);
177 lua_pushinteger(luastate, 0);
187 static int LuaPacketSport(
lua_State *luastate)
190 if (s == NULL || s->
p == NULL) {
199 lua_pushinteger(luastate,
p->
sp);
202 LUA_ERROR(
"sp only available for tcp, udp and sctp");
212 static int LuaPacketDport(
lua_State *luastate)
215 if (s == NULL || s->
p == NULL) {
224 lua_pushinteger(luastate,
p->
dp);
227 LUA_ERROR(
"dp only available for tcp, udp and sctp");
233 static int LuaPacketGet(
lua_State *luastate)
245 luaL_getmetatable(luastate, suricata_packet);
246 lua_setmetatable(luastate, -2);
250 static const luaL_Reg packetlib[] = {
252 {
"get", LuaPacketGet },
257 static const luaL_Reg packetlib_meta[] = {
259 {
"packet", LuaPacketPacket },
260 {
"payload", LuaPacketPayload },
261 {
"pcap_cnt", LuaPacketPcapCnt },
262 {
"timestring_legacy", LuaPacketTimestringLegacy },
263 {
"timestring_iso8601", LuaPacketTimestringIso8601 },
264 {
"timestamp", LuaPacketTimestamp },
265 {
"tuple", LuaPacketTuple },
266 {
"sp", LuaPacketSport },
267 {
"dp", LuaPacketDport },
268 {
"__gc", LuaPacketGC },
275 luaL_newmetatable(luastate, suricata_packet);
276 lua_pushvalue(luastate, -1);
277 lua_setfield(luastate, -2,
"__index");
278 luaL_setfuncs(luastate, packetlib_meta, 0);
280 luaL_newlib(luastate, packetlib);