Go to the documentation of this file.
67 void *state,
void *txv,
const Signature *s,
71 static void DetectLuaRegisterTests(
void);
74 static int g_smtp_generic_list_id = 0;
102 #define FLAG_DATATYPE_PACKET BIT_U32(0)
103 #define FLAG_DATATYPE_PAYLOAD BIT_U32(1)
104 #define FLAG_DATATYPE_STREAM BIT_U32(2)
105 #define FLAG_DATATYPE_BUFFER BIT_U32(22)
106 #define FLAG_ERROR_LOGGED BIT_U32(23)
107 #define FLAG_BLOCKED_FUNCTION_LOGGED BIT_U32(24)
108 #define FLAG_INSTRUCTION_LIMIT_LOGGED BIT_U32(25)
109 #define FLAG_MEMORY_LIMIT_LOGGED BIT_U32(26)
111 #define DEFAULT_LUA_ALLOC_LIMIT 500000
112 #define DEFAULT_LUA_INSTRUCTION_LIMIT 500000
117 int size = lua_gettop(state);
118 printf(
"%s: size %d\n", prefix, size);
120 for (
int i = 1; i <= size; i++) {
121 int type = lua_type(state, i);
122 printf(
"- %s: Stack size=%d, level=%d, type=%d, ", prefix, size, i,
type);
126 printf(
"function %s", lua_tostring(state, i));
129 printf(
"bool %s", lua_toboolean(state, i) ?
"true" :
"false");
132 printf(
"number %g", lua_tonumber(state, i));
135 printf(
"string `%s'", lua_tostring(state, i));
138 printf(
"table `%s'", lua_tostring(state, i));
141 printf(
"other %s", lua_typename(state,
type));
153 static int DetectLuaRunMatch(
159 if (lua_pcall(tlua->
luastate, 1, 1, 0) != 0) {
160 const char *reason = lua_tostring(tlua->
luastate, -1);
171 reason =
"memory limit exceeded";
179 if (!(tlua->
flags & flag)) {
180 SCLogWarning(
"Lua script failed to run successfully: %s", reason);
185 while (lua_gettop(tlua->
luastate) > 0) {
194 if (lua_gettop(tlua->
luastate) > 0) {
196 if (lua_type(tlua->
luastate, 1) == LUA_TNUMBER) {
197 double script_ret = lua_tonumber(tlua->
luastate, 1);
201 if (script_ret == 1.0)
205 }
else if (lua_type(tlua->
luastate, 1) == LUA_TTABLE) {
208 while (lua_next(tlua->
luastate, -2)) {
209 v = lua_tostring(tlua->
luastate, -1);
211 k = lua_tostring(tlua->
luastate, -1);
218 if (strcmp(k,
"retval") == 0) {
222 "for \"retval\" from LUA return table: '%s'",
246 while (lua_gettop(tlua->
luastate) > 0) {
259 if (buffer == NULL || buffer_len == 0)
274 lua_getglobal(tlua->
luastate,
"match");
277 lua_pushliteral(tlua->
luastate,
"offset");
285 SCReturnInt(DetectLuaRunMatch(det_ctx, lua, tlua));
315 flags = STREAM_TOSERVER;
317 flags = STREAM_TOCLIENT;
328 lua_getglobal(tlua->
luastate,
"match");
331 SCReturnInt(DetectLuaRunMatch(det_ctx, lua, tlua));
350 lua_getglobal(tlua->
luastate,
"match");
353 SCReturnInt(DetectLuaRunMatch(det_ctx, lua, tlua));
369 void *state,
void *txv,
const Signature *s,
372 return DetectLuaAppMatchCommon(det_ctx, f,
flags, state, s,
ctx);
378 static const char *ut_script = NULL;
381 static void *DetectLuaThreadInit(
void *data)
412 if (ut_script != NULL) {
413 status = luaL_loadbuffer(t->
luastate, ut_script, strlen(ut_script),
"unittest");
430 if (lua_pcall(t->
luastate, 0, 0, 0) != 0) {
436 lua_getglobal(t->
luastate,
"thread_init");
437 if (lua_isfunction(t->
luastate, -1)) {
438 if (lua_pcall(t->
luastate, 0, 0, 0) != 0) {
439 SCLogError(
"couldn't run script 'thread_init' function: %s",
456 static void DetectLuaThreadFree(
void *
ctx)
484 if (strlen(
str) &&
str[0] ==
'!') {
499 DetectLuaFree(
de_ctx, lua);
508 if (luastate == NULL)
511 luaL_openlibs(luastate);
519 if (ut_script != NULL) {
520 status = luaL_loadbuffer(luastate, ut_script, strlen(ut_script),
"unittest");
522 SCLogError(
"couldn't load file: %s", lua_tostring(luastate, -1));
527 status = luaL_loadfile(luastate, ld->
filename);
529 SCLogError(
"couldn't load file: %s", lua_tostring(luastate, -1));
537 if (lua_pcall(luastate, 0, 0, 0) != 0) {
538 SCLogError(
"couldn't prime file: %s", lua_tostring(luastate, -1));
542 lua_getglobal(luastate,
"init");
543 if (lua_type(luastate, -1) != LUA_TFUNCTION) {
548 if (lua_pcall(luastate, 0, 1, 0) != 0) {
549 SCLogError(
"couldn't run script 'init' function: %s", lua_tostring(luastate, -1));
554 if (lua_gettop(luastate) == 0) {
555 SCLogError(
"init function in script should return table, nothing returned");
558 if (lua_type(luastate, 1) != LUA_TTABLE) {
559 SCLogError(
"init function in script should return table, returned is not table");
563 lua_pushnil(luastate);
565 while (lua_next(luastate, -2)) {
566 k = lua_tostring(luastate, -2);
571 if (strcmp(k,
"flowvar") == 0) {
572 if (lua_istable(luastate, -1)) {
573 lua_pushnil(luastate);
574 while (lua_next(luastate, -2) != 0) {
576 const char *value = lua_tostring(luastate, -1);
579 lua_pop(luastate, 1);
591 lua_pop(luastate, 1);
593 }
else if (strcmp(k,
"flowint") == 0) {
594 if (lua_istable(luastate, -1)) {
595 lua_pushnil(luastate);
596 while (lua_next(luastate, -2) != 0) {
598 const char *value = lua_tostring(luastate, -1);
601 lua_pop(luastate, 1);
613 lua_pop(luastate, 1);
615 }
else if (strcmp(k,
"bytevar") == 0) {
616 if (lua_istable(luastate, -1)) {
617 lua_pushnil(luastate);
618 while (lua_next(luastate, -2) != 0) {
620 const char *value = lua_tostring(luastate, -1);
623 lua_pop(luastate, 1);
632 SCLogError(
"Unknown byte_extract or byte_math var "
633 "requested by lua script - %s",
641 lua_pop(luastate, 1);
645 bool required = lua_toboolean(luastate, -1);
646 lua_pop(luastate, 1);
651 if (strcmp(k,
"packet") == 0) {
653 }
else if (strcmp(k,
"payload") == 0) {
655 }
else if (strcmp(k,
"buffer") == 0) {
663 }
else if (strcmp(k,
"stream") == 0) {
672 }
else if (strncmp(k,
"http", 4) == 0 || strncmp(k,
"dns", 3) == 0 ||
673 strncmp(k,
"tls", 3) == 0 || strncmp(k,
"ssh", 3) == 0 ||
674 strncmp(k,
"smtp", 4) == 0 || strncmp(k,
"dnp3", 4) == 0) {
675 SCLogError(
"data type %s no longer supported, use rule hooks", k);
685 lua_pop(luastate, 1);
709 if (
SCConfGetBool(
"security.lua.allow-rules", &enabled) == 1 && !enabled) {
710 SCLogError(
"Lua rules disabled by security configuration: security.lua.allow-rules");
721 (void)
SCConfGetInt(
"security.lua.max-bytes", &lua_alloc_limit);
722 (void)
SCConfGetInt(
"security.lua.max-instructions", &lua_instruction_limit);
726 int allow_restricted_functions = 0;
727 (void)
SCConfGetBool(
"security.lua.allow-restricted-functions", &allow_restricted_functions);
730 if (DetectLuaSetupPrime(
de_ctx, lua, s) == -1) {
735 DetectLuaThreadInit, (
void *)lua,
736 DetectLuaThreadFree, 0);
742 if (list == -1 || (list == 0 && s->
init_data->
list == INT_MAX)) {
767 DetectLuaFree(
de_ctx, lua);
786 for (uint16_t i = 0; i < lua->
flowints; i++) {
789 for (uint16_t i = 0; i < lua->
flowvars; i++) {
803 static int LuaMatchTest01(
void)
807 const char script[] =
"function init (args)\n"
808 " local needs = {}\n"
809 " needs[\"flowvar\"] = {\"cnt\"}\n"
813 "function match(args)\n"
814 " a = ScFlowvarGet(0)\n"
816 " a = tostring(tonumber(a)+1)\n"
818 " ScFlowvarSet(0, a, #a)\n"
822 " ScFlowvarSet(0, a, #a)\n"
825 " print (\"pre check: \" .. (a))\n"
826 " if tonumber(a) == 2 then\n"
833 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
836 "POST / HTTP/1.1\r\n"
837 "Host: www.emergingthreats.net\r\n\r\n";
839 "POST / HTTP/1.1\r\n"
840 "Host: www.openinfosecfoundation.org\r\n\r\n";
841 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
842 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
852 memset(&th_v, 0,
sizeof(th_v));
853 memset(&f, 0,
sizeof(f));
854 memset(&ssn, 0,
sizeof(ssn));
861 f.
proto = IPPROTO_TCP;
927 static int LuaMatchTest01a(
void)
929 const char script[] =
"function init (args)\n"
930 " local needs = {}\n"
931 " needs[\"flowvar\"] = {\"cnt\"}\n"
935 "function match(args)\n"
936 " a = SCFlowvarGet(0)\n"
938 " a = tostring(tonumber(a)+1)\n"
940 " SCFlowvarSet(0, a, #a)\n"
944 " SCFlowvarSet(0, a, #a)\n"
947 " print (\"pre check: \" .. (a))\n"
948 " if tonumber(a) == 2 then\n"
955 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
957 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
958 "Host: www.emergingthreats.net\r\n\r\n";
959 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
960 "Host: www.openinfosecfoundation.org\r\n\r\n";
961 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
962 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
972 memset(&th_v, 0,
sizeof(th_v));
973 memset(&f, 0,
sizeof(f));
974 memset(&ssn, 0,
sizeof(ssn));
981 f.
proto = IPPROTO_TCP;
1048 static int LuaMatchTest02(
void)
1050 const char script[] =
"function init (args)\n"
1051 " local needs = {}\n"
1052 " needs[\"payload\"] = tostring(true)\n"
1053 " needs[\"flowvar\"] = {\"cnt\"}\n"
1057 "function match(args)\n"
1058 " a = ScFlowvarGet(0)\n"
1060 " a = tostring(tonumber(a)+1)\n"
1062 " ScFlowvarSet(0, a, #a)\n"
1064 " a = tostring(1)\n"
1066 " ScFlowvarSet(0, a, #a)\n"
1069 " print (\"pre check: \" .. (a))\n"
1070 " if tonumber(a) == 2 then\n"
1071 " print \"match\"\n"
1077 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1078 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1079 "Host: www.emergingthreats.net\r\n\r\n";
1080 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1081 "Host: www.openinfosecfoundation.org\r\n\r\n";
1082 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1083 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1091 memset(&th_v, 0,
sizeof(th_v));
1092 memset(&f, 0,
sizeof(f));
1093 memset(&ssn, 0,
sizeof(ssn));
1100 f.
proto = IPPROTO_TCP;
1155 static int LuaMatchTest02a(
void)
1157 const char script[] =
"function init (args)\n"
1158 " local needs = {}\n"
1159 " needs[\"payload\"] = tostring(true)\n"
1160 " needs[\"flowvar\"] = {\"cnt\"}\n"
1164 "function match(args)\n"
1165 " a = SCFlowvarGet(0)\n"
1167 " a = tostring(tonumber(a)+1)\n"
1169 " SCFlowvarSet(0, a, #a)\n"
1171 " a = tostring(1)\n"
1173 " SCFlowvarSet(0, a, #a)\n"
1176 " print (\"pre check: \" .. (a))\n"
1177 " if tonumber(a) == 2 then\n"
1178 " print \"match\"\n"
1184 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1185 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1186 "Host: www.emergingthreats.net\r\n\r\n";
1187 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1188 "Host: www.openinfosecfoundation.org\r\n\r\n";
1189 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1190 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1198 memset(&th_v, 0,
sizeof(th_v));
1199 memset(&f, 0,
sizeof(f));
1200 memset(&ssn, 0,
sizeof(ssn));
1207 f.
proto = IPPROTO_TCP;
1261 static int LuaMatchTest03(
void)
1263 const char script[] =
"function init (args)\n"
1264 " local needs = {}\n"
1265 " needs[\"packet\"] = tostring(true)\n"
1266 " needs[\"flowvar\"] = {\"cnt\"}\n"
1270 "function match(args)\n"
1271 " a = ScFlowvarGet(0)\n"
1273 " a = tostring(tonumber(a)+1)\n"
1275 " ScFlowvarSet(0, a, #a)\n"
1277 " a = tostring(1)\n"
1279 " ScFlowvarSet(0, a, #a)\n"
1282 " print (\"pre check: \" .. (a))\n"
1283 " if tonumber(a) == 2 then\n"
1284 " print \"match\"\n"
1290 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1291 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1292 "Host: www.emergingthreats.net\r\n\r\n";
1293 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1294 "Host: www.openinfosecfoundation.org\r\n\r\n";
1295 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1296 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1304 memset(&th_v, 0,
sizeof(th_v));
1305 memset(&f, 0,
sizeof(f));
1306 memset(&ssn, 0,
sizeof(ssn));
1313 f.
proto = IPPROTO_TCP;
1367 static int LuaMatchTest03a(
void)
1369 const char script[] =
"function init (args)\n"
1370 " local needs = {}\n"
1371 " needs[\"packet\"] = tostring(true)\n"
1372 " needs[\"flowvar\"] = {\"cnt\"}\n"
1376 "function match(args)\n"
1377 " a = SCFlowvarGet(0)\n"
1379 " a = tostring(tonumber(a)+1)\n"
1381 " SCFlowvarSet(0, a, #a)\n"
1383 " a = tostring(1)\n"
1385 " SCFlowvarSet(0, a, #a)\n"
1388 " print (\"pre check: \" .. (a))\n"
1389 " if tonumber(a) == 2 then\n"
1390 " print \"match\"\n"
1396 char sig[] =
"alert tcp any any -> any any (flow:to_server; lua:unittest; sid:1;)";
1397 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1398 "Host: www.emergingthreats.net\r\n\r\n";
1399 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1400 "Host: www.openinfosecfoundation.org\r\n\r\n";
1401 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1402 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1410 memset(&th_v, 0,
sizeof(th_v));
1411 memset(&f, 0,
sizeof(f));
1412 memset(&ssn, 0,
sizeof(ssn));
1419 f.
proto = IPPROTO_TCP;
1472 static int LuaMatchTest04(
void)
1474 const char script[] =
"function init (args)\n"
1475 " local needs = {}\n"
1476 " needs[\"flowint\"] = {\"cnt\"}\n"
1480 "function match(args)\n"
1481 " print \"inspecting\""
1482 " a = ScFlowintGet(0)\n"
1484 " ScFlowintSet(0, a + 1)\n"
1486 " ScFlowintSet(0, 1)\n"
1489 " a = ScFlowintGet(0)\n"
1491 " print \"match\"\n"
1497 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1499 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n"
1500 "Host: www.emergingthreats.net\r\n\r\n";
1501 uint8_t httpbuf2[] =
"POST / HTTP/1.1\r\n"
1502 "Host: www.openinfosecfoundation.org\r\n\r\n";
1503 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1504 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1514 memset(&th_v, 0,
sizeof(th_v));
1515 memset(&f, 0,
sizeof(f));
1516 memset(&ssn, 0,
sizeof(ssn));
1523 f.
proto = IPPROTO_TCP;
1588 static int LuaMatchTest04a(
void)
1590 const char script[] =
"function init (args)\n"
1591 " local needs = {}\n"
1592 " needs[\"flowint\"] = {\"cnt\"}\n"
1596 "function match(args)\n"
1597 " print \"inspecting\""
1598 " a = SCFlowintGet(0)\n"
1600 " SCFlowintSet(0, a + 1)\n"
1602 " SCFlowintSet(0, 1)\n"
1605 " a = SCFlowintGet(0)\n"
1607 " print \"match\"\n"
1613 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1615 uint8_t httpbuf1[] =
1616 "POST / HTTP/1.1\r\n"
1617 "Host: www.emergingthreats.net\r\n\r\n";
1618 uint8_t httpbuf2[] =
1619 "POST / HTTP/1.1\r\n"
1620 "Host: www.openinfosecfoundation.org\r\n\r\n";
1621 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1622 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1632 memset(&th_v, 0,
sizeof(th_v));
1633 memset(&f, 0,
sizeof(f));
1634 memset(&ssn, 0,
sizeof(ssn));
1641 f.
proto = IPPROTO_TCP;
1706 static int LuaMatchTest05(
void)
1708 const char script[] =
"function init (args)\n"
1709 " local needs = {}\n"
1710 " needs[\"flowint\"] = {\"cnt\"}\n"
1714 "function match(args)\n"
1715 " print \"inspecting\""
1716 " a = ScFlowintIncr(0)\n"
1718 " print \"match\"\n"
1724 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1726 uint8_t httpbuf1[] =
1727 "POST / HTTP/1.1\r\n"
1728 "Host: www.emergingthreats.net\r\n\r\n";
1729 uint8_t httpbuf2[] =
1730 "POST / HTTP/1.1\r\n"
1731 "Host: www.openinfosecfoundation.org\r\n\r\n";
1732 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1733 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1743 memset(&th_v, 0,
sizeof(th_v));
1744 memset(&f, 0,
sizeof(f));
1745 memset(&ssn, 0,
sizeof(ssn));
1752 f.
proto = IPPROTO_TCP;
1817 static int LuaMatchTest05a(
void)
1819 const char script[] =
"function init (args)\n"
1820 " local needs = {}\n"
1821 " needs[\"flowint\"] = {\"cnt\"}\n"
1825 "function match(args)\n"
1826 " print \"inspecting\""
1827 " a = SCFlowintIncr(0)\n"
1829 " print \"match\"\n"
1835 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1837 uint8_t httpbuf1[] =
1838 "POST / HTTP/1.1\r\n"
1839 "Host: www.emergingthreats.net\r\n\r\n";
1840 uint8_t httpbuf2[] =
1841 "POST / HTTP/1.1\r\n"
1842 "Host: www.openinfosecfoundation.org\r\n\r\n";
1843 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1844 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1854 memset(&th_v, 0,
sizeof(th_v));
1855 memset(&f, 0,
sizeof(f));
1856 memset(&ssn, 0,
sizeof(ssn));
1863 f.
proto = IPPROTO_TCP;
1928 static int LuaMatchTest06(
void)
1930 const char script[] =
"function init (args)\n"
1931 " local needs = {}\n"
1932 " needs[\"flowint\"] = {\"cnt\"}\n"
1936 "function match(args)\n"
1937 " print \"inspecting\""
1938 " a = ScFlowintGet(0)\n"
1939 " if a == nil then\n"
1940 " print \"new var set to 2\""
1941 " ScFlowintSet(0, 2)\n"
1943 " a = ScFlowintDecr(0)\n"
1945 " print \"match\"\n"
1951 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
1953 uint8_t httpbuf1[] =
1954 "POST / HTTP/1.1\r\n"
1955 "Host: www.emergingthreats.net\r\n\r\n";
1956 uint8_t httpbuf2[] =
1957 "POST / HTTP/1.1\r\n"
1958 "Host: www.openinfosecfoundation.org\r\n\r\n";
1959 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1960 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1970 memset(&th_v, 0,
sizeof(th_v));
1971 memset(&f, 0,
sizeof(f));
1972 memset(&ssn, 0,
sizeof(ssn));
1979 f.
proto = IPPROTO_TCP;
2044 static int LuaMatchTest06a(
void)
2046 const char script[] =
"function init (args)\n"
2047 " local needs = {}\n"
2048 " needs[\"flowint\"] = {\"cnt\"}\n"
2052 "function match(args)\n"
2053 " print \"inspecting\""
2054 " a = SCFlowintGet(0)\n"
2055 " if a == nil then\n"
2056 " print \"new var set to 2\""
2057 " SCFlowintSet(0, 2)\n"
2059 " a = SCFlowintDecr(0)\n"
2061 " print \"match\"\n"
2067 char sig[] =
"alert http1:request_complete any any -> any any (flow:to_server; lua:unittest; "
2069 uint8_t httpbuf1[] =
2070 "POST / HTTP/1.1\r\n"
2071 "Host: www.emergingthreats.net\r\n\r\n";
2072 uint8_t httpbuf2[] =
2073 "POST / HTTP/1.1\r\n"
2074 "Host: www.openinfosecfoundation.org\r\n\r\n";
2075 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
2076 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
2086 memset(&th_v, 0,
sizeof(th_v));
2087 memset(&f, 0,
sizeof(f));
2088 memset(&ssn, 0,
sizeof(ssn));
2095 f.
proto = IPPROTO_TCP;
2159 void DetectLuaRegisterTests(
void)
#define FLAG_MEMORY_LIMIT_LOGGED
void LuaStateSetThreadVars(lua_State *luastate, ThreadVars *tv)
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
void StatsIncr(ThreadVars *tv, uint16_t id)
Increments the local counter.
SigTableElmt * sigmatch_table
void(* Free)(DetectEngineCtx *, void *)
#define FLAG_BLOCKED_FUNCTION_LOGGED
void * DetectThreadCtxGetKeywordThreadCtx(DetectEngineThreadCtx *det_ctx, int id)
Retrieve thread local keyword ctx by id.
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
SCLuaSbState * SCLuaSbGetContext(lua_State *L)
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
int allow_restricted_functions
#define FLAG_INSTRUCTION_LIMIT_LOGGED
main detection engine ctx
uint16_t lua_blocked_function_errors
#define DEFAULT_LUA_INSTRUCTION_LIMIT
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
#define DETECT_LUA_MAX_FLOWVARS
void AppLayerParserThreadCtxFree(AppLayerParserThreadCtx *tctx)
Destroys the app layer parser thread context obtained using AppLayerParserThreadCtxAlloc().
#define FLOW_PKT_TOSERVER
int SCConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
Packet * UTHBuildPacket(uint8_t *payload, uint16_t payload_len, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
uint32_t flowvar[DETECT_LUA_MAX_FLOWVARS]
int StringParseInt32(int32_t *res, int base, size_t len, const char *str)
uint32_t VarNameStoreRegister(const char *name, const enum VarTypes type)
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
uint16_t lua_instruction_limit_errors
int DetectBufferGetActiveList(DetectEngineCtx *de_ctx, Signature *s)
#define SIG_FLAG_TOCLIENT
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
#define FLAG_DATATYPE_PACKET
uint8_t DetectByteIndexType
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
struct lua_State lua_State
void StreamTcpInitConfig(bool)
To initialize the stream global configuration data.
#define FLOW_INITIALIZE(f)
#define SIG_FLAG_TOSERVER
uint32_t VarNameStoreLookupByName(const char *name, const enum VarTypes type)
find name for id+type at packet time.
#define PASS
Pass the test.
uint64_t instruction_limit
int SCConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
AppLayerParserThreadCtx * alp_tctx
Per thread variable structure.
void DetectLuaRegister(void)
Registration function for keyword: lua.
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
void VarNameStoreUnregister(const uint32_t id, const enum VarTypes type)
#define DETECT_LUA_MAX_BYTEVARS
#define DETECT_LUA_MAX_FLOWINTS
#define FLAG_DATATYPE_PAYLOAD
#define SCLogWarning(...)
Macro used to log WARNING messages.
int DetectLuaMatchBuffer(DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchData *smd, const uint8_t *buffer, uint32_t buffer_len, uint32_t offset, Flow *f)
@ SIGNATURE_HOOK_TYPE_NOT_SET
uint32_t bytevar[DETECT_LUA_MAX_BYTEVARS]
uint16_t lua_memory_limit_errors
#define FLAG_DATATYPE_STREAM
void SCLuaSbStateClose(lua_State *L)
uint32_t flowint[DETECT_LUA_MAX_FLOWINTS]
#define FLAG_ERROR_LOGGED
SignatureInitData * init_data
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
void SCLuaRequirefBuiltIns(lua_State *L)
Register Suricata built-in modules for loading in a non-sandboxed environment.
bool blocked_function_error
#define FLOW_PKT_TOCLIENT
void LuaExtensionsMatchSetup(lua_State *lua_state, DetectLuaData *ld, DetectEngineThreadCtx *det_ctx, Flow *f, Packet *p, const Signature *s, uint8_t flags)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
void LuaDumpStack(lua_State *state, const char *prefix)
dump stack from lua state to screen
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
int SCConfSetFinal(const char *name, const char *val)
Set a final configuration value.
AppLayerParserThreadCtx * AppLayerParserThreadCtxAlloc(void)
Gets a new app layer protocol's parser thread context.
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
void SCLuaSbLoadLibs(lua_State *L)
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
bool DetectByteRetrieveSMVar(const char *arg, const Signature *s, DetectByteIndexType *index)
Used to retrieve args from BM.
int DetectBufferTypeRegister(const char *name)
void StreamTcpFreeConfig(bool quiet)
int DetectRegisterThreadCtxFuncs(DetectEngineCtx *de_ctx, const char *name, void *(*InitFunc)(void *), void *data, void(*FreeFunc)(void *), int mode)
Register Thread keyword context Funcs.
int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow *f, AppProto alproto, uint8_t flags, const uint8_t *input, uint32_t input_len)
#define DEFAULT_LUA_ALLOC_LIMIT
enum SignatureHookType type
void SCLuaSbResetInstructionCounter(lua_State *L)
uint8_t DetectEngineInspectGenericList(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Do the content inspection & validation for a signature.
#define SCLogError(...)
Macro used to log ERROR messages.
#define FLAG_DATATYPE_BUFFER
#define FLOW_PKT_ESTABLISHED
DetectEngineCtx * DetectEngineCtxInit(void)
int LuaRegisterExtensions(lua_State *lua_state)
Register Suricata Lua functions.
bool instruction_count_error
char * DetectLoadCompleteSigPath(const DetectEngineCtx *de_ctx, const char *sig_file)
Create the path if default-rule-path was specified.
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
lua_State * SCLuaSbStateNew(uint64_t alloclimit, uint64_t instructionlimit)
Allocate a new Lua sandbox.
SigMatch * SigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
FlowVar * FlowVarGet(Flow *f, uint32_t idx)
get the flowvar with index 'idx' from the flow
int DetectUnregisterThreadCtxFuncs(DetectEngineCtx *de_ctx, void *data, const char *name)
Remove Thread keyword context registration.
AppProto alproto
application level protocol
void(* RegisterTests)(void)
union FlowVar_::@113 data
int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len)
void UTHFreePackets(Packet **p, int numpkts)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself.