28 static const char suricata_bytevar_mt[] =
"suricata:bytevar:mt";
45 return luaL_error(L,
"bytevar API not available in this context");
50 return luaL_error(L,
"bytevar.map() must be called from init()");
52 if (!lua_islightuserdata(L, -2)) {
53 return luaL_error(L,
"bytevar.map: first argument must be the signature passed to init");
58 if (lua_touserdata(L, -2) != (
void *)ld->
signature) {
59 return luaL_error(L,
"bytevar.map: first argument is not the signature passed to init");
61 const Signature *s = lua_touserdata(L, -2);
62 const char *
name = luaL_checkstring(L, -1);
65 for (uint16_t i = 0; i < ld->
bytevars; i++) {
73 return luaL_error(L,
"too many bytevars mapped");
78 return luaL_error(L,
"unknown byte_extract or byte_math variable: %s",
name);
83 return luaL_error(L,
"failed to allocate memory for bytevar name: %s",
name);
92 const char *
name = luaL_checkstring(L, 1);
95 return luaL_error(L,
"internal error: no lua data");
98 for (uint16_t i = 0; i < ld->
bytevars; i++) {
101 if (handle == NULL) {
106 luaL_getmetatable(L, suricata_bytevar_mt);
107 lua_setmetatable(L, -2);
112 return luaL_error(L,
"unknown bytevar: %s",
name);
118 if (handle == NULL) {
123 if (det_ctx == NULL) {
128 if ((int32_t)handle->
id < 0 || (int32_t)handle->
id > max_id) {
152 static const luaL_Reg bytevarlib[] = {
154 {
"map", LuaBytevarMap, },
155 {
"get", LuaBytevarGet, },
160 static const luaL_Reg bytevarmt[] = {
162 {
"value", LuaBytevarValue, },
169 luaL_newmetatable(L, suricata_bytevar_mt);
170 lua_pushvalue(L, -1);
171 lua_setfield(L, -2,
"__index");
172 luaL_setfuncs(L, bytevarmt, 0);
174 luaL_newlib(L, bytevarlib);