38static const char suricata_packet[] =
"suricata:packet";
44static int LuaPacketGC(
lua_State *luastate)
54static int LuaPacketPayload(
lua_State *luastate)
57 if (s == NULL || s->
p == NULL) {
65static int LuaPacketPacket(
lua_State *luastate)
68 if (s == NULL || s->
p == NULL) {
76static int LuaPacketPcapCnt(
lua_State *luastate)
79 if (s == NULL || s->
p == NULL) {
83 lua_pushinteger(luastate, s->
p->
pcap_cnt);
90static int LuaPacketTimestringLegacy(
lua_State *luastate)
93 if (s == NULL || s->
p == NULL) {
99 lua_pushstring(luastate, timebuf);
103static int LuaPacketTimestringIso8601(
lua_State *luastate)
106 if (s == NULL || s->
p == NULL) {
112 lua_pushstring(luastate, timebuf);
116static int LuaPacketTimestamp(
lua_State *luastate)
119 if (s == NULL || s->
p == NULL) {
136static 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) {
176 lua_pushinteger(luastate, 0);
177 lua_pushinteger(luastate, 0);
187static 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");
212static 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");
233static int LuaPacketGet(
lua_State *luastate)
245 luaL_getmetatable(luastate, suricata_packet);
246 lua_setmetatable(luastate, -2);
250static const luaL_Reg packetlib[] = {
252 {
"get", LuaPacketGet },
257static 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);
#define GET_IPV6_DST_ADDR(p)
#define GET_IPV4_SRC_ADDR_PTR(p)
#define GET_IPV6_SRC_ADDR(p)
#define GET_IPV4_DST_ADDR_PTR(p)
struct Packet_::@33::@40 icmp_s
struct lua_State lua_State
const char lua_ext_key_p[]
int LuaLoadPacketLib(lua_State *luastate)
int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len)
Packet * LuaStateGetPacket(lua_State *luastate)
get packet pointer from the lua state
const char * PrintInet(int af, const void *src, char *dst, socklen_t size)
void CreateTimeString(const SCTime_t ts, char *str, size_t size)
void CreateIsoTimeString(const SCTime_t ts, char *str, size_t size)