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);
146 static int LuaCallbackFlowTimestampsPushToStack(
149 lua_pushnumber(luastate, (
double)
SCTIME_SECS(startts));
150 lua_pushnumber(luastate, (
double)
SCTIME_SECS(lastts));
151 lua_pushnumber(luastate, (
double)
SCTIME_USECS(startts));
160 static int LuaCallbackFlowTimestamps(
lua_State *luastate)
167 return LuaCallbackFlowTimestampsPushToStack(luastate, flow->
startts, flow->
lastts);
178 static int LuaCallbackTimeStringPushToStackFromFlow(
lua_State *luastate,
const Flow *flow)
182 lua_pushstring (luastate, timebuf);
190 static int LuaCallbackFlowTimeString(
lua_State *luastate)
197 r = LuaCallbackTimeStringPushToStackFromFlow(luastate, flow);
210 static int LuaCallbackHasAlertsPushToStackFromFlow(
lua_State *luastate,
const Flow *flow)
221 static int LuaCallbackFlowHasAlerts(
lua_State *luastate)
228 r = LuaCallbackHasAlertsPushToStackFromFlow(luastate, flow);
242 static int LuaCallbackTuplePushToStackFromFlow(
lua_State *luastate,
const Flow *f)
250 lua_pushinteger(luastate, ipver);
254 char srcip[46] =
"", dstip[46] =
"";
256 PrintInet(AF_INET, (
const void *)&(f->
src.addr_data32[0]), srcip,
sizeof(srcip));
257 PrintInet(AF_INET, (
const void *)&(f->
dst.addr_data32[0]), dstip,
sizeof(dstip));
263 lua_pushstring (luastate, srcip);
264 lua_pushstring (luastate, dstip);
267 lua_pushinteger(luastate, f->
proto);
268 if (f->
proto == IPPROTO_TCP || f->
proto == IPPROTO_UDP) {
269 lua_pushinteger(luastate, f->
sp);
270 lua_pushinteger(luastate, f->
dp);
272 }
else if (f->
proto == IPPROTO_ICMP || f->
proto == IPPROTO_ICMPV6) {
273 lua_pushinteger(luastate, f->
icmp_s.type);
274 lua_pushinteger(luastate, f->
icmp_s.code);
276 lua_pushinteger(luastate, 0);
277 lua_pushinteger(luastate, 0);
287 static int LuaCallbackTupleFlow(
lua_State *luastate)
294 r = LuaCallbackTuplePushToStackFromFlow(luastate, f);
307 static int LuaCallbackAppLayerProtoPushToStackFromFlow(
lua_State *luastate,
const AppProto alproto)
312 lua_pushstring(luastate,
string);
320 static int LuaCallbackAppLayerProtoFlow(
lua_State *luastate)
327 r = LuaCallbackAppLayerProtoPushToStackFromFlow(luastate, f->
alproto);
328 r += LuaCallbackAppLayerProtoPushToStackFromFlow(luastate, f->
alproto_ts);
329 r += LuaCallbackAppLayerProtoPushToStackFromFlow(luastate, f->
alproto_tc);
330 r += LuaCallbackAppLayerProtoPushToStackFromFlow(luastate, f->
alproto_orig);
331 r += LuaCallbackAppLayerProtoPushToStackFromFlow(luastate, f->
alproto_expect);
344 static int LuaCallbackStatsPushToStackFromFlow(
lua_State *luastate,
const Flow *f)
357 static int LuaCallbackStatsFlow(
lua_State *luastate)
364 r = LuaCallbackStatsPushToStackFromFlow(luastate, f);
377 static int LuaCallbackPushFlowIdToStackFromFlow(
lua_State *luastate,
const Flow *f)
379 int64_t
id = FlowGetId(f);
380 lua_pushinteger(luastate,
id);
388 static int LuaCallbackFlowId(
lua_State *luastate)
395 r = LuaCallbackPushFlowIdToStackFromFlow(luastate, f);
408 static int LuaCallbackRuleIdsPushToStackFromSignature(
lua_State *luastate,
const Signature *s)
410 lua_pushinteger(luastate, s->
id);
411 lua_pushinteger(luastate, s->
rev);
412 lua_pushinteger(luastate, s->
gid);
423 static int LuaCallbackRuleIds(
lua_State *luastate)
432 return LuaCallbackError(luastate,
"internal error: no packet alert or signature");
434 return LuaCallbackRuleIdsPushToStackFromSignature(luastate, s);
445 static int LuaCallbackRuleActionPushToStackFromSignature(
lua_State *luastate,
const Signature *s)
447 const char *action =
"";
458 lua_pushstring(luastate, action);
469 static int LuaCallbackRuleAction(
lua_State *luastate)
478 return LuaCallbackError(luastate,
"internal error: no packet alert or signature");
480 return LuaCallbackRuleActionPushToStackFromSignature(luastate, s);
491 static int LuaCallbackRuleMsgPushToStackFromSignature(
lua_State *luastate,
const Signature *s)
493 lua_pushstring(luastate, s->
msg);
504 static int LuaCallbackRuleMsg(
lua_State *luastate)
513 return LuaCallbackError(luastate,
"internal error: no packet alert or signature");
515 return LuaCallbackRuleMsgPushToStackFromSignature(luastate, s);
526 static int LuaCallbackRuleClassPushToStackFromSignature(
lua_State *luastate,
const Signature *s)
529 lua_pushinteger(luastate, s->
prio);
540 static int LuaCallbackRuleClass(
lua_State *luastate)
549 return LuaCallbackError(luastate,
"internal error: no packet alert or signature");
551 return LuaCallbackRuleClassPushToStackFromSignature(luastate, s);
554 static int LuaCallbackLogPath(
lua_State *luastate)
563 static int LuaCallbackLogDebug(
lua_State *luastate)
567 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
572 static int LuaCallbackLogInfo(
lua_State *luastate)
576 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
579 lua_getstack(luastate, 1, &ar);
580 lua_getinfo(luastate,
"nSl", &ar);
581 const char *funcname = ar.name ? ar.name : ar.what;
586 static int LuaCallbackLogNotice(
lua_State *luastate)
590 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
593 lua_getstack(luastate, 1, &ar);
594 lua_getinfo(luastate,
"nSl", &ar);
595 const char *funcname = ar.name ? ar.name : ar.what;
600 static int LuaCallbackLogWarning(
lua_State *luastate)
604 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
607 lua_getstack(luastate, 1, &ar);
608 lua_getinfo(luastate,
"nSl", &ar);
609 const char *funcname = ar.name ? ar.name : ar.what;
614 static int LuaCallbackLogError(
lua_State *luastate)
618 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
620 lua_getstack(luastate, 1, &ar);
621 lua_getinfo(luastate,
"nSl", &ar);
622 const char *funcname = ar.name ? ar.name : ar.what;
637 static int LuaCallbackFileInfoPushToStackFromFile(
lua_State *luastate,
const File *file)
640 char *sha1ptr = NULL;
641 char *sha256ptr = NULL;
647 for (x = 0; x <
sizeof(file->
md5); x++) {
649 snprintf(one,
sizeof(one),
"%02x", file->
md5[x]);
650 strlcat(md5, one,
sizeof(md5));
657 for (x = 0; x <
sizeof(file->
sha1); x++) {
659 snprintf(one,
sizeof(one),
"%02x", file->
sha1[x]);
660 strlcat(sha1, one,
sizeof(sha1));
663 char sha256[65] =
"";
667 for (x = 0; x <
sizeof(file->
sha256); x++) {
669 snprintf(one,
sizeof(one),
"%02x", file->
sha256[x]);
670 strlcat(sha256, one,
sizeof(sha256));
676 lua_pushinteger(luastate, tx_id);
677 lua_pushlstring(luastate, (
char *)file->
name, file->
name_len);
679 lua_pushstring (luastate,
686 lua_pushstring(luastate, md5ptr);
687 lua_pushstring(luastate, sha1ptr);
688 lua_pushstring(luastate, sha256ptr);
696 static int LuaCallbackFileInfo(
lua_State *luastate)
702 return LuaCallbackFileInfoPushToStackFromFile(luastate, file);
713 static int LuaCallbackFileStatePushToStackFromFile(
lua_State *luastate,
const File *file)
715 const char *state =
"UNKNOWN";
716 switch (file->
state) {
736 lua_pushstring (luastate, state);
745 static int LuaCallbackFileState(
lua_State *luastate)
751 return LuaCallbackFileStatePushToStackFromFile(luastate, file);
765 lua_pushinteger (luastate, (lua_Integer)tid);
766 lua_pushstring (luastate,
tv->
name);
775 static int LuaCallbackThreadInfo(
lua_State *luastate)
781 return LuaCallbackThreadInfoPushToStackFromThreadVars(luastate,
tv);
787 lua_pushcfunction(luastate, LuaCallbackFlowTimestamps);
788 lua_setglobal(luastate,
"SCFlowTimestamps");
789 lua_pushcfunction(luastate, LuaCallbackFlowTimeString);
790 lua_setglobal(luastate,
"SCFlowTimeString");
791 lua_pushcfunction(luastate, LuaCallbackTupleFlow);
792 lua_setglobal(luastate,
"SCFlowTuple");
793 lua_pushcfunction(luastate, LuaCallbackAppLayerProtoFlow);
794 lua_setglobal(luastate,
"SCFlowAppLayerProto");
795 lua_pushcfunction(luastate, LuaCallbackStatsFlow);
796 lua_setglobal(luastate,
"SCFlowStats");
797 lua_pushcfunction(luastate, LuaCallbackFlowHasAlerts);
798 lua_setglobal(luastate,
"SCFlowHasAlerts");
799 lua_pushcfunction(luastate, LuaCallbackFlowId);
800 lua_setglobal(luastate,
"SCFlowId");
802 lua_pushcfunction(luastate, LuaCallbackStreamingBuffer);
803 lua_setglobal(luastate,
"SCStreamingBuffer");
805 lua_pushcfunction(luastate, LuaCallbackLogPath);
806 lua_setglobal(luastate,
"SCLogPath");
808 lua_pushcfunction(luastate, LuaCallbackLogDebug);
809 lua_setglobal(luastate,
"SCLogDebug");
810 lua_pushcfunction(luastate, LuaCallbackLogInfo);
811 lua_setglobal(luastate,
"SCLogInfo");
812 lua_pushcfunction(luastate, LuaCallbackLogNotice);
813 lua_setglobal(luastate,
"SCLogNotice");
814 lua_pushcfunction(luastate, LuaCallbackLogWarning);
815 lua_setglobal(luastate,
"SCLogWarning");
816 lua_pushcfunction(luastate, LuaCallbackLogError);
817 lua_setglobal(luastate,
"SCLogError");
820 lua_pushcfunction(luastate, LuaCallbackRuleIds);
821 lua_setglobal(luastate,
"SCRuleIds");
822 lua_pushcfunction(luastate, LuaCallbackRuleAction);
823 lua_setglobal(luastate,
"SCRuleAction");
824 lua_pushcfunction(luastate, LuaCallbackRuleMsg);
825 lua_setglobal(luastate,
"SCRuleMsg");
826 lua_pushcfunction(luastate, LuaCallbackRuleClass);
827 lua_setglobal(luastate,
"SCRuleClass");
829 lua_pushcfunction(luastate, LuaCallbackFileInfo);
830 lua_setglobal(luastate,
"SCFileInfo");
831 lua_pushcfunction(luastate, LuaCallbackFileState);
832 lua_setglobal(luastate,
"SCFileState");
834 lua_pushcfunction(luastate, LuaCallbackThreadInfo);
835 lua_setglobal(luastate,
"SCThreadInfo");
848 return (alproto == flow_alproto);