61 lua_pushnil(luastate);
62 lua_pushstring(luastate,
msg);
69 if (!lua_isstring(luastate, argc))
71 const char *
str = lua_tostring(luastate, argc);
81 lua_pushstring(luastate, key);
82 lua_pushnumber(luastate, value);
83 lua_settable(luastate, -3);
92 lua_pushstring(luastate, key);
93 lua_pushstring(luastate, value ? value :
"(null)");
94 lua_settable(luastate, -3);
99 lua_pushstring(luastate, key);
101 lua_settable(luastate, -3);
115 lua_pushlstring (luastate, (
const char *)b->
data, b->
data_len);
127 static int LuaCallbackStreamingBuffer(
lua_State *luastate)
133 return LuaCallbackStreamingBufferPushToStack(luastate, b);
144 static int LuaCallbackPacketPayloadPushToStackFromPacket(
lua_State *luastate,
const Packet *p)
154 static int LuaCallbackPacketPayload(
lua_State *luastate)
160 return LuaCallbackPacketPayloadPushToStackFromPacket(luastate, p);
186 static int LuaCallbackTimeStringPushToStackFromPacket(
lua_State *luastate,
const Packet *p)
190 lua_pushstring (luastate, timebuf);
198 static int LuaCallbackPacketTimestamp(
lua_State *luastate)
204 return LuaCallbackTimestampPushToStack(luastate, p->
ts);
211 static int LuaCallbackPacketTimeString(
lua_State *luastate)
217 return LuaCallbackTimeStringPushToStackFromPacket(luastate, p);
230 static int LuaCallbackFlowTimestampsPushToStack(
233 lua_pushnumber(luastate, (
double)
SCTIME_SECS(startts));
234 lua_pushnumber(luastate, (
double)
SCTIME_SECS(lastts));
235 lua_pushnumber(luastate, (
double)
SCTIME_USECS(startts));
244 static int LuaCallbackFlowTimestamps(
lua_State *luastate)
251 return LuaCallbackFlowTimestampsPushToStack(luastate, flow->
startts, flow->
lastts);
262 static int LuaCallbackTimeStringPushToStackFromFlow(
lua_State *luastate,
const Flow *flow)
266 lua_pushstring (luastate, timebuf);
274 static int LuaCallbackFlowTimeString(
lua_State *luastate)
281 r = LuaCallbackTimeStringPushToStackFromFlow(luastate, flow);
294 static int LuaCallbackHasAlertsPushToStackFromFlow(
lua_State *luastate,
const Flow *flow)
305 static int LuaCallbackFlowHasAlerts(
lua_State *luastate)
312 r = LuaCallbackHasAlertsPushToStackFromFlow(luastate, flow);
326 static int LuaCallbackTuplePushToStackFromPacket(
lua_State *luastate,
const Packet *p)
329 if (PacketIsIPv4(p)) {
331 }
else if (PacketIsIPv6(p)) {
334 lua_pushinteger(luastate, ipver);
338 char srcip[46] =
"", dstip[46] =
"";
339 if (PacketIsIPv4(p)) {
342 }
else if (PacketIsIPv6(p)) {
347 lua_pushstring (luastate, srcip);
348 lua_pushstring (luastate, dstip);
351 lua_pushinteger(luastate, p->
proto);
352 if (p->
proto == IPPROTO_TCP || p->
proto == IPPROTO_UDP) {
353 lua_pushinteger(luastate, p->
sp);
354 lua_pushinteger(luastate, p->
dp);
356 }
else if (p->
proto == IPPROTO_ICMP || p->
proto == IPPROTO_ICMPV6) {
357 lua_pushinteger(luastate, p->
icmp_s.type);
358 lua_pushinteger(luastate, p->
icmp_s.code);
360 lua_pushinteger(luastate, 0);
361 lua_pushinteger(luastate, 0);
371 static int LuaCallbackTuple(
lua_State *luastate)
377 return LuaCallbackTuplePushToStackFromPacket(luastate, p);
389 static int LuaCallbackTuplePushToStackFromFlow(
lua_State *luastate,
const Flow *f)
397 lua_pushinteger(luastate, ipver);
401 char srcip[46] =
"", dstip[46] =
"";
403 PrintInet(AF_INET, (
const void *)&(f->
src.addr_data32[0]), srcip,
sizeof(srcip));
404 PrintInet(AF_INET, (
const void *)&(f->
dst.addr_data32[0]), dstip,
sizeof(dstip));
410 lua_pushstring (luastate, srcip);
411 lua_pushstring (luastate, dstip);
414 lua_pushinteger(luastate, f->
proto);
415 if (f->
proto == IPPROTO_TCP || f->
proto == IPPROTO_UDP) {
416 lua_pushinteger(luastate, f->
sp);
417 lua_pushinteger(luastate, f->
dp);
419 }
else if (f->
proto == IPPROTO_ICMP || f->
proto == IPPROTO_ICMPV6) {
420 lua_pushinteger(luastate, f->
icmp_s.type);
421 lua_pushinteger(luastate, f->
icmp_s.code);
423 lua_pushinteger(luastate, 0);
424 lua_pushinteger(luastate, 0);
434 static int LuaCallbackTupleFlow(
lua_State *luastate)
441 r = LuaCallbackTuplePushToStackFromFlow(luastate, f);
454 static int LuaCallbackAppLayerProtoPushToStackFromFlow(
lua_State *luastate,
const AppProto alproto)
459 lua_pushstring(luastate,
string);
467 static int LuaCallbackAppLayerProtoFlow(
lua_State *luastate)
474 r = LuaCallbackAppLayerProtoPushToStackFromFlow(luastate, f->
alproto);
475 r += LuaCallbackAppLayerProtoPushToStackFromFlow(luastate, f->
alproto_ts);
476 r += LuaCallbackAppLayerProtoPushToStackFromFlow(luastate, f->
alproto_tc);
477 r += LuaCallbackAppLayerProtoPushToStackFromFlow(luastate, f->
alproto_orig);
478 r += LuaCallbackAppLayerProtoPushToStackFromFlow(luastate, f->
alproto_expect);
491 static int LuaCallbackStatsPushToStackFromFlow(
lua_State *luastate,
const Flow *f)
504 static int LuaCallbackStatsFlow(
lua_State *luastate)
511 r = LuaCallbackStatsPushToStackFromFlow(luastate, f);
524 static int LuaCallbackPushFlowIdToStackFromFlow(
lua_State *luastate,
const Flow *f)
526 int64_t
id = FlowGetId(f);
527 lua_pushinteger(luastate,
id);
535 static int LuaCallbackFlowId(
lua_State *luastate)
542 r = LuaCallbackPushFlowIdToStackFromFlow(luastate, f);
555 static int LuaCallbackRuleIdsPushToStackFromSignature(
lua_State *luastate,
const Signature *s)
557 lua_pushinteger(luastate, s->
id);
558 lua_pushinteger(luastate, s->
rev);
559 lua_pushinteger(luastate, s->
gid);
570 static int LuaCallbackRuleIds(
lua_State *luastate)
579 return LuaCallbackError(luastate,
"internal error: no packet alert or signature");
581 return LuaCallbackRuleIdsPushToStackFromSignature(luastate, s);
592 static int LuaCallbackRuleActionPushToStackFromSignature(
lua_State *luastate,
const Signature *s)
594 const char *action =
"";
605 lua_pushstring(luastate, action);
616 static int LuaCallbackRuleAction(
lua_State *luastate)
625 return LuaCallbackError(luastate,
"internal error: no packet alert or signature");
627 return LuaCallbackRuleActionPushToStackFromSignature(luastate, s);
638 static int LuaCallbackRuleMsgPushToStackFromSignature(
lua_State *luastate,
const Signature *s)
640 lua_pushstring(luastate, s->
msg);
651 static int LuaCallbackRuleMsg(
lua_State *luastate)
660 return LuaCallbackError(luastate,
"internal error: no packet alert or signature");
662 return LuaCallbackRuleMsgPushToStackFromSignature(luastate, s);
673 static int LuaCallbackRuleClassPushToStackFromSignature(
lua_State *luastate,
const Signature *s)
676 lua_pushinteger(luastate, s->
prio);
687 static int LuaCallbackRuleClass(
lua_State *luastate)
696 return LuaCallbackError(luastate,
"internal error: no packet alert or signature");
698 return LuaCallbackRuleClassPushToStackFromSignature(luastate, s);
701 static int LuaCallbackLogPath(
lua_State *luastate)
710 static int LuaCallbackLogDebug(
lua_State *luastate)
714 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
719 static int LuaCallbackLogInfo(
lua_State *luastate)
723 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
726 lua_getstack(luastate, 1, &ar);
727 lua_getinfo(luastate,
"nSl", &ar);
728 const char *funcname = ar.name ? ar.name : ar.what;
733 static int LuaCallbackLogNotice(
lua_State *luastate)
737 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
740 lua_getstack(luastate, 1, &ar);
741 lua_getinfo(luastate,
"nSl", &ar);
742 const char *funcname = ar.name ? ar.name : ar.what;
747 static int LuaCallbackLogWarning(
lua_State *luastate)
751 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
754 lua_getstack(luastate, 1, &ar);
755 lua_getinfo(luastate,
"nSl", &ar);
756 const char *funcname = ar.name ? ar.name : ar.what;
761 static int LuaCallbackLogError(
lua_State *luastate)
765 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
767 lua_getstack(luastate, 1, &ar);
768 lua_getinfo(luastate,
"nSl", &ar);
769 const char *funcname = ar.name ? ar.name : ar.what;
784 static int LuaCallbackFileInfoPushToStackFromFile(
lua_State *luastate,
const File *file)
787 char *sha1ptr = NULL;
788 char *sha256ptr = NULL;
794 for (x = 0; x <
sizeof(file->
md5); x++) {
796 snprintf(one,
sizeof(one),
"%02x", file->
md5[x]);
797 strlcat(md5, one,
sizeof(md5));
804 for (x = 0; x <
sizeof(file->
sha1); x++) {
806 snprintf(one,
sizeof(one),
"%02x", file->
sha1[x]);
807 strlcat(sha1, one,
sizeof(sha1));
810 char sha256[65] =
"";
814 for (x = 0; x <
sizeof(file->
sha256); x++) {
816 snprintf(one,
sizeof(one),
"%02x", file->
sha256[x]);
817 strlcat(sha256, one,
sizeof(sha256));
823 lua_pushinteger(luastate, tx_id);
824 lua_pushlstring(luastate, (
char *)file->
name, file->
name_len);
826 lua_pushstring (luastate,
833 lua_pushstring(luastate, md5ptr);
834 lua_pushstring(luastate, sha1ptr);
835 lua_pushstring(luastate, sha256ptr);
843 static int LuaCallbackFileInfo(
lua_State *luastate)
849 return LuaCallbackFileInfoPushToStackFromFile(luastate, file);
860 static int LuaCallbackFileStatePushToStackFromFile(
lua_State *luastate,
const File *file)
862 const char *state =
"UNKNOWN";
863 switch (file->
state) {
883 lua_pushstring (luastate, state);
892 static int LuaCallbackFileState(
lua_State *luastate)
898 return LuaCallbackFileStatePushToStackFromFile(luastate, file);
912 lua_pushinteger (luastate, (lua_Integer)tid);
913 lua_pushstring (luastate,
tv->
name);
922 static int LuaCallbackThreadInfo(
lua_State *luastate)
928 return LuaCallbackThreadInfoPushToStackFromThreadVars(luastate,
tv);
934 lua_pushcfunction(luastate, LuaCallbackPacketPayload);
935 lua_setglobal(luastate,
"SCPacketPayload");
936 lua_pushcfunction(luastate, LuaCallbackPacketTimestamp);
937 lua_setglobal(luastate,
"SCPacketTimestamp");
938 lua_pushcfunction(luastate, LuaCallbackPacketTimeString);
939 lua_setglobal(luastate,
"SCPacketTimeString");
940 lua_pushcfunction(luastate, LuaCallbackTuple);
941 lua_setglobal(luastate,
"SCPacketTuple");
943 lua_pushcfunction(luastate, LuaCallbackFlowTimestamps);
944 lua_setglobal(luastate,
"SCFlowTimestamps");
945 lua_pushcfunction(luastate, LuaCallbackFlowTimeString);
946 lua_setglobal(luastate,
"SCFlowTimeString");
947 lua_pushcfunction(luastate, LuaCallbackTupleFlow);
948 lua_setglobal(luastate,
"SCFlowTuple");
949 lua_pushcfunction(luastate, LuaCallbackAppLayerProtoFlow);
950 lua_setglobal(luastate,
"SCFlowAppLayerProto");
951 lua_pushcfunction(luastate, LuaCallbackStatsFlow);
952 lua_setglobal(luastate,
"SCFlowStats");
953 lua_pushcfunction(luastate, LuaCallbackFlowHasAlerts);
954 lua_setglobal(luastate,
"SCFlowHasAlerts");
955 lua_pushcfunction(luastate, LuaCallbackFlowId);
956 lua_setglobal(luastate,
"SCFlowId");
958 lua_pushcfunction(luastate, LuaCallbackStreamingBuffer);
959 lua_setglobal(luastate,
"SCStreamingBuffer");
961 lua_pushcfunction(luastate, LuaCallbackLogPath);
962 lua_setglobal(luastate,
"SCLogPath");
964 lua_pushcfunction(luastate, LuaCallbackLogDebug);
965 lua_setglobal(luastate,
"SCLogDebug");
966 lua_pushcfunction(luastate, LuaCallbackLogInfo);
967 lua_setglobal(luastate,
"SCLogInfo");
968 lua_pushcfunction(luastate, LuaCallbackLogNotice);
969 lua_setglobal(luastate,
"SCLogNotice");
970 lua_pushcfunction(luastate, LuaCallbackLogWarning);
971 lua_setglobal(luastate,
"SCLogWarning");
972 lua_pushcfunction(luastate, LuaCallbackLogError);
973 lua_setglobal(luastate,
"SCLogError");
976 lua_pushcfunction(luastate, LuaCallbackRuleIds);
977 lua_setglobal(luastate,
"SCRuleIds");
978 lua_pushcfunction(luastate, LuaCallbackRuleAction);
979 lua_setglobal(luastate,
"SCRuleAction");
980 lua_pushcfunction(luastate, LuaCallbackRuleMsg);
981 lua_setglobal(luastate,
"SCRuleMsg");
982 lua_pushcfunction(luastate, LuaCallbackRuleClass);
983 lua_setglobal(luastate,
"SCRuleClass");
985 lua_pushcfunction(luastate, LuaCallbackFileInfo);
986 lua_setglobal(luastate,
"SCFileInfo");
987 lua_pushcfunction(luastate, LuaCallbackFileState);
988 lua_setglobal(luastate,
"SCFileState");
990 lua_pushcfunction(luastate, LuaCallbackThreadInfo);
991 lua_setglobal(luastate,
"SCThreadInfo");
1004 return (alproto == flow_alproto);