suricata
output-lua.c
Go to the documentation of this file.
1 /* Copyright (C) 2014-2022 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  *
23  */
24 
25 #include "suricata-common.h"
26 #include "output-lua.h"
27 #include "action-globals.h"
28 #include "util-lua-builtins.h"
29 #include "util-debug.h"
30 #include "output.h"
31 #include "app-layer-htp.h"
32 #include "app-layer-ssl.h"
33 #include "app-layer-ssh.h"
34 #include "app-layer-parser.h"
35 #include "util-path.h"
36 #include "util-lua.h"
37 #include "util-lua-common.h"
38 #include "util-lua-http.h"
39 #include "util-lua-smtp.h"
40 
41 #define MODULE_NAME "LuaLog"
42 
43 /** \brief structure containing global config
44  * The OutputLuaLogInitSub which is run per script
45  * can access this to get global config info through
46  * it's parent_ctx->data ptr.
47  */
48 typedef struct LogLuaMasterCtx_ {
49  /** \brief Path to script directory. */
50  char script_dir[PATH_MAX];
51 
52  /** \brief Lua search path for Lua modules. */
53  char path[PATH_MAX];
54 
55  /** \brief Lua search path for C modules. */
56  char cpath[PATH_MAX];
58 
59 typedef struct LogLuaCtx_ {
63  /* invocation counter for the state's generation slot: the state is
64  * shared and the logger's mutex is held across the invocation, so
65  * the per-invocation bump is serialized */
66  uint64_t invocation_gen;
68 
69 typedef struct LogLuaThreadCtx_ {
72 
73 static TmEcode LuaLogThreadInit(ThreadVars *t, const void *initdata, void **data);
74 static TmEcode LuaLogThreadDeinit(ThreadVars *t, void *data);
75 
76 /** \internal
77  * \brief TX logger for lua scripts
78  *
79  * A single call to this function will run one script on a single
80  * transaction.
81  *
82  * NOTE: The flow (f) also referenced by p->flow is locked.
83  */
84 static bool LuaTlsTxLogCondition(
85  ThreadVars *tv, const Packet *p, void *state, void *tx, uint64_t tx_id)
86 {
87  /* keep in sync with the json-tls logger gate */
88  return SSLV3TxLogReady(tx);
89 }
90 
91 static int LuaTxLogger(ThreadVars *tv, void *thread_data, const Packet *p, Flow *f, void *alstate,
92  void *txptr, uint64_t tx_id)
93 {
94  SCEnter();
95 
96  LogLuaThreadCtx *td = (LogLuaThreadCtx *)thread_data;
97 
98  SCMutexLock(&td->lua_ctx->m);
99  /* a peer thread's deinit may have closed the shared state */
100  if (td->lua_ctx->luastate == NULL) {
101  SCMutexUnlock(&td->lua_ctx->m);
102  SCReturnInt(0);
103  }
104 
107  LuaStateSetTX(td->lua_ctx->luastate, txptr, tx_id);
109 
110  /* prepare data to pass to script */
111  lua_getglobal(td->lua_ctx->luastate, "log");
112  lua_newtable(td->lua_ctx->luastate);
113  LuaPushTableKeyValueInt(td->lua_ctx->luastate, "tx_id", (int)(tx_id));
114 
115  int retval = lua_pcall(td->lua_ctx->luastate, 1, 0, 0);
116  if (retval != 0) {
117  SCLogInfo("failed to run script: %s", lua_tostring(td->lua_ctx->luastate, -1));
118  /* a failed pcall leaves the error object on the stack */
119  lua_pop(td->lua_ctx->luastate, 1);
120  }
121 
122  SCMutexUnlock(&td->lua_ctx->m);
123  SCReturnInt(0);
124 }
125 
126 /** \internal
127  * \brief Streaming logger for lua scripts
128  *
129  * Hooks into the Streaming Logger API. Gets called for each chunk of new
130  * streaming data.
131  */
132 static int LuaStreamingLogger(ThreadVars *tv, void *thread_data, const Flow *f, const uint8_t *data,
133  uint32_t data_len, uint64_t tx_id, uint8_t flags)
134 {
135  SCEnter();
136 
137  void *txptr = NULL;
138 
139  SCLogDebug("flags %02x", flags);
140 
142  if (f && f->alstate)
143  txptr = AppLayerParserGetTx(f->proto, f->alproto, f->alstate, tx_id);
144  }
145 
146  LogLuaThreadCtx *td = (LogLuaThreadCtx *)thread_data;
147  SCMutexLock(&td->lua_ctx->m);
148  /* a peer thread's deinit may have closed the shared state */
149  if (td->lua_ctx->luastate == NULL) {
150  SCMutexUnlock(&td->lua_ctx->m);
151  SCReturnInt(0);
152  }
153  lua_State *luastate = td->lua_ctx->luastate;
154 
155  LuaStateSetThreadVars(luastate, tv);
156  /* txptr is already NULL for non-transaction chunks: write the entry
157  * unconditionally so the registry cannot keep a previous tx */
158  LuaStateSetTX(luastate, txptr, txptr ? tx_id : 0);
159  LuaStateSetFlow(luastate, (Flow *)f);
160 
161  /* prepare data to pass to script */
162  lua_getglobal(luastate, "log");
163  lua_newtable(luastate);
164 
166  LuaPushTableKeyValueInt(luastate, "tx_id", (int)(tx_id));
167 
168  /* create the "stream" subtable */
169  lua_pushstring(luastate, "stream");
170  lua_newtable(luastate);
171 
172  LuaPushTableKeyValueLString(luastate, "data", (const char *)data, data_len);
177 
178  /* set the "stream" subtable into the main args table */
179  lua_settable(luastate, -3);
180 
181  int retval = lua_pcall(luastate, 1, 0, 0);
182  if (retval != 0) {
183  SCLogInfo("failed to run script: %s", lua_tostring(td->lua_ctx->luastate, -1));
184  /* a failed pcall leaves the error object on the stack */
185  lua_pop(td->lua_ctx->luastate, 1);
186  }
187 
188  SCMutexUnlock(&td->lua_ctx->m);
189 
191 }
192 
193 /** \internal
194  * \brief Packet Logger for lua scripts, for alerts
195  *
196  * A single call to this function will run one script for a single
197  * packet. If it is called, it means that the registered condition
198  * function has returned true.
199  *
200  * The script is called once for each alert stored in the packet.
201  *
202  * NOTE: p->flow is UNlocked
203  */
204 static int LuaPacketLoggerAlerts(ThreadVars *tv, void *thread_data, const Packet *p)
205 {
206  LogLuaThreadCtx *td = (LogLuaThreadCtx *)thread_data;
207 
208  char timebuf[64];
209  CreateTimeString(p->ts, timebuf, sizeof(timebuf));
210 
211  if (!(PacketIsIPv4(p)) && !(PacketIsIPv6(p))) {
212  /* decoder event */
213  goto not_supported;
214  }
215 
216  /* loop through alerts stored in the packet */
217  SCMutexLock(&td->lua_ctx->m);
218  /* a peer thread's deinit may have closed the shared state */
219  if (td->lua_ctx->luastate == NULL) {
220  SCMutexUnlock(&td->lua_ctx->m);
221  SCReturnInt(0);
222  }
223  uint16_t cnt;
224  for (cnt = 0; cnt < p->alerts.cnt; cnt++) {
225  const PacketAlert *pa = &p->alerts.alerts[cnt];
226  if (unlikely((pa->s == NULL) || (pa->action & ACTION_ALERT) == 0)) {
227  continue;
228  }
229 
230  lua_getglobal(td->lua_ctx->luastate, "log");
231 
232  void *txptr = NULL;
233  if (p->flow && p->flow->alstate && (pa->flags & PACKET_ALERT_FLAG_TX))
234  txptr = AppLayerParserGetTx(
235  p->flow->proto, p->flow->alproto, p->flow->alstate, pa->tx_id);
236 
239  LuaStateSetTX(td->lua_ctx->luastate, txptr, pa->tx_id);
242 
243  /* prepare data to pass to script */
244  // lua_newtable(td->lua_ctx->luastate);
245 
246  int retval = lua_pcall(td->lua_ctx->luastate, 0, 0, 0);
247  if (retval != 0) {
248  SCLogInfo("failed to run script: %s", lua_tostring(td->lua_ctx->luastate, -1));
249  /* a failed pcall leaves the error object on the stack */
250  lua_pop(td->lua_ctx->luastate, 1);
251  }
252  }
253  SCMutexUnlock(&td->lua_ctx->m);
254 not_supported:
255  SCReturnInt(0);
256 }
257 
258 static bool LuaPacketConditionAlerts(ThreadVars *tv, void *data, const Packet *p)
259 {
260  return (p->alerts.cnt > 0);
261 }
262 
263 /** \internal
264  * \brief Packet Logger for lua scripts, for packets
265  *
266  * A single call to this function will run one script for a single
267  * packet. If it is called, it means that the registered condition
268  * function has returned true.
269  *
270  * The script is called once for each packet.
271  *
272  * NOTE: p->flow is UNlocked
273  */
274 static int LuaPacketLogger(ThreadVars *tv, void *thread_data, const Packet *p)
275 {
276  LogLuaThreadCtx *td = (LogLuaThreadCtx *)thread_data;
277 
278  char timebuf[64];
279 
280  if ((!(PacketIsIPv4(p))) && (!(PacketIsIPv6(p)))) {
281  goto not_supported;
282  }
283 
284  CreateTimeString(p->ts, timebuf, sizeof(timebuf));
285 
286  /* loop through alerts stored in the packet */
287  SCMutexLock(&td->lua_ctx->m);
288  /* a peer thread's deinit may have closed the shared state */
289  if (td->lua_ctx->luastate == NULL) {
290  SCMutexUnlock(&td->lua_ctx->m);
291  SCReturnInt(0);
292  }
293  lua_getglobal(td->lua_ctx->luastate, "log");
294 
298 
299  /* prepare data to pass to script */
300  lua_newtable(td->lua_ctx->luastate);
301 
302  int retval = lua_pcall(td->lua_ctx->luastate, 1, 0, 0);
303  if (retval != 0) {
304  SCLogInfo("failed to run script: %s", lua_tostring(td->lua_ctx->luastate, -1));
305  /* a failed pcall leaves the error object on the stack */
306  lua_pop(td->lua_ctx->luastate, 1);
307  }
308  SCMutexUnlock(&td->lua_ctx->m);
309 not_supported:
310  SCReturnInt(0);
311 }
312 
313 static bool LuaPacketCondition(ThreadVars *tv, void *data, const Packet *p)
314 {
315  return true;
316 }
317 
318 /** \internal
319  * \brief File API Logger function for Lua scripts
320  *
321  * Executes a script once for one file.
322  *
323  * NOTE p->flow is locked at this point
324  */
325 static int LuaFileLogger(ThreadVars *tv, void *thread_data, const Packet *p, const File *ff,
326  void *tx, const uint64_t tx_id, uint8_t dir)
327 {
328  SCEnter();
329  LogLuaThreadCtx *td = (LogLuaThreadCtx *)thread_data;
330 
331  if ((!(PacketIsIPv4(p))) && (!(PacketIsIPv6(p))))
332  return 0;
333 
335 
336  SCLogDebug("ff %p", ff);
337 
338  SCMutexLock(&td->lua_ctx->m);
339  /* a peer thread's deinit may have closed the shared state */
340  if (td->lua_ctx->luastate == NULL) {
341  SCMutexUnlock(&td->lua_ctx->m);
342  SCReturnInt(0);
343  }
344 
347  LuaStateSetTX(td->lua_ctx->luastate, tx, tx_id);
349  LuaStateSetFile(td->lua_ctx->luastate, (File *)ff);
350  /* the file's container direction - on the EOF opposing-direction
351  * flush this is the packet's opposite direction */
352  LuaStateSetDirection(td->lua_ctx->luastate, (dir & STREAM_TOSERVER) ? 1 : 0);
353 
354  /* get the lua function to call */
355  lua_getglobal(td->lua_ctx->luastate, "log");
356 
357  int retval = lua_pcall(td->lua_ctx->luastate, 0, 0, 0);
358  if (retval != 0) {
359  SCLogInfo("failed to run script: %s", lua_tostring(td->lua_ctx->luastate, -1));
360  /* a failed pcall leaves the error object on the stack */
361  lua_pop(td->lua_ctx->luastate, 1);
362  }
363  SCMutexUnlock(&td->lua_ctx->m);
364  return 0;
365 }
366 
367 /** \internal
368  * \brief Flow API Logger function for Lua scripts
369  *
370  * Executes a script once for one flow
371  *
372  * Note: flow 'f' is locked
373  */
374 static int LuaFlowLogger(ThreadVars *tv, void *thread_data, Flow *f)
375 {
376  SCEnter();
377  LogLuaThreadCtx *td = (LogLuaThreadCtx *)thread_data;
378 
379  SCLogDebug("f %p", f);
380 
381  SCMutexLock(&td->lua_ctx->m);
382  /* a peer thread's deinit may have closed the shared state */
383  if (td->lua_ctx->luastate == NULL) {
384  SCMutexUnlock(&td->lua_ctx->m);
385  SCReturnInt(0);
386  }
387 
390 
391  /* get the lua function to call */
392  lua_getglobal(td->lua_ctx->luastate, "log");
393 
394  int retval = lua_pcall(td->lua_ctx->luastate, 0, 0, 0);
395  if (retval != 0) {
396  SCLogInfo("failed to run script: %s", lua_tostring(td->lua_ctx->luastate, -1));
397  /* a failed pcall leaves the error object on the stack */
398  lua_pop(td->lua_ctx->luastate, 1);
399  }
400  SCMutexUnlock(&td->lua_ctx->m);
401  return 0;
402 }
403 
404 static int LuaStatsLogger(ThreadVars *tv, void *thread_data, const StatsTable *st)
405 {
406  SCEnter();
407  LogLuaThreadCtx *td = (LogLuaThreadCtx *)thread_data;
408 
409  SCMutexLock(&td->lua_ctx->m);
410  /* a peer thread's deinit may have closed the shared state */
411  if (td->lua_ctx->luastate == NULL) {
412  SCMutexUnlock(&td->lua_ctx->m);
413  SCReturnInt(0);
414  }
415 
416  lua_State *luastate = td->lua_ctx->luastate;
417  /* get the lua function to call */
418  lua_getglobal(td->lua_ctx->luastate, "log");
419 
420  /* create lua array, which is really just a table. The key is an int (1-x),
421  * the value another table with named fields: name, tm_name, value, pvalue.
422  * { 1, { name=<name>, tmname=<tm_name>, value=<value>, pvalue=<pvalue>}}
423  * { 2, { name=<name>, tmname=<tm_name>, value=<value>, pvalue=<pvalue>}}
424  * etc
425  */
426  lua_newtable(luastate);
427  uint32_t u = 0;
428  for (; u < st->nstats; u++) {
429  lua_pushinteger(luastate, u + 1);
430 
431  lua_newtable(luastate);
432 
433  lua_pushstring(luastate, "name");
434  lua_pushstring(luastate, st->stats[u].name);
435  lua_settable(luastate, -3);
436 
437  lua_pushstring(luastate, "tmname");
438  lua_pushstring(luastate, st->stats[u].tm_name);
439  lua_settable(luastate, -3);
440 
441  lua_pushstring(luastate, "value");
442  lua_pushinteger(luastate, st->stats[u].value);
443  lua_settable(luastate, -3);
444 
445  lua_pushstring(luastate, "pvalue");
446  lua_pushinteger(luastate, st->stats[u].pvalue);
447  lua_settable(luastate, -3);
448 
449  lua_settable(luastate, -3);
450  }
451 
452  int retval = lua_pcall(td->lua_ctx->luastate, 1, 0, 0);
453  if (retval != 0) {
454  SCLogInfo("failed to run script: %s", lua_tostring(td->lua_ctx->luastate, -1));
455  /* a failed pcall leaves the error object on the stack */
456  lua_pop(td->lua_ctx->luastate, 1);
457  }
458  SCMutexUnlock(&td->lua_ctx->m);
459  return 0;
460 }
461 
462 typedef struct LogLuaScriptOptions_ {
464  int packet;
465  int alerts;
466  int file;
468  int tcp_data;
470  int flow;
471  int stats;
473 
474 /** \brief Setup or clear Lua module search paths.
475  *
476  * If search paths are provided by the configuration, set them up,
477  * otherwise clear the default search paths.
478  */
479 static void LuaSetPaths(lua_State *L, LogLuaMasterCtx *ctx)
480 {
481  lua_getglobal(L, "package");
482 
483  if (strlen(ctx->path) > 0) {
484  lua_pushstring(L, ctx->path);
485  } else {
486  lua_pushstring(L, "");
487  }
488  lua_setfield(L, -2, "path");
489 
490  if (strlen(ctx->cpath) > 0) {
491  lua_pushstring(L, ctx->cpath);
492  } else {
493  lua_pushstring(L, "");
494  }
495  lua_setfield(L, -2, "cpath");
496 
497  /* Pop package. */
498  lua_pop(L, 1);
499 }
500 
501 /** \brief load and evaluate the script
502  *
503  * This function parses the script, checks if all the required functions
504  * are defined and runs the 'init' function. The init function will inform
505  * us what the scripts needs are.
506  *
507  * \param filename filename of lua script file
508  * \param options struct to pass script requirements/options back to caller
509  * \retval errcode 0 ok, -1 error
510  */
511 static int LuaScriptInit(const char *filename, LogLuaScriptOptions *options, LogLuaMasterCtx *ctx)
512 {
513  lua_State *luastate = LuaGetState();
514  if (luastate == NULL)
515  goto error;
516  luaL_openlibs(luastate);
517  SCLuaRequirefBuiltIns(luastate);
518  LuaSetPaths(luastate, ctx);
519 
520  int status = luaL_loadfile(luastate, filename);
521  if (status) {
522  SCLogError("couldn't load file: %s", lua_tostring(luastate, -1));
523  goto error;
524  }
525 
526  /* prime the script (or something) */
527  if (lua_pcall(luastate, 0, 0, 0) != 0) {
528  SCLogError("couldn't prime file: %s", lua_tostring(luastate, -1));
529  goto error;
530  }
531 
532  lua_getglobal(luastate, "init");
533  if (lua_type(luastate, -1) != LUA_TFUNCTION) {
534  SCLogError("no init function in script");
535  goto error;
536  }
537 
538  if (lua_pcall(luastate, 0, 1, 0) != 0) {
539  SCLogError("couldn't run script 'init' function: %s", lua_tostring(luastate, -1));
540  goto error;
541  }
542 
543  /* process returns from script */
544  if (lua_gettop(luastate) == 0) {
545  SCLogError("init function in script should return table, nothing returned");
546  goto error;
547  }
548  if (lua_type(luastate, 1) != LUA_TTABLE) {
549  SCLogError("init function in script should return table, returned is not table");
550  goto error;
551  }
552 
553  lua_pushnil(luastate);
554  const char *k, *v;
555  while (lua_next(luastate, -2)) {
556  /* only string keys name an option. lua_tostring() on a number
557  * key converts it in place and the next lua_next() then raises
558  * "invalid key to 'next'" outside any pcall (abort) */
559  if (lua_type(luastate, -2) != LUA_TSTRING) {
560  lua_pop(luastate, 1);
561  continue;
562  }
563  k = lua_tostring(luastate, -2);
564 
565  v = lua_tostring(luastate, -1);
566  lua_pop(luastate, 1);
567  if (v == NULL)
568  continue;
569 
570  SCLogDebug("k='%s', v='%s'", k, v);
571 
572  if (strcmp(k, "streaming") == 0) {
573  options->streaming = 1;
574  if (strcmp(v, "http") == 0) {
575  options->alproto = ALPROTO_HTTP1;
576  } else if (strcmp(v, "tcp") == 0) {
577  options->tcp_data = 1;
578  } else {
579  SCLogError("unsupported streaming argument: %s", v);
580  goto error;
581  }
582  } else if (strcmp(k, "protocol") == 0 && strcmp(v, "http") == 0)
583  options->alproto = ALPROTO_HTTP1;
584  else if (strcmp(k, "protocol") == 0 && strcmp(v, "dns") == 0)
585  options->alproto = ALPROTO_DNS;
586  else if (strcmp(k, "protocol") == 0 && strcmp(v, "tls") == 0)
587  options->alproto = ALPROTO_TLS;
588  else if (strcmp(k, "protocol") == 0 && strcmp(v, "ssh") == 0)
589  options->alproto = ALPROTO_SSH;
590  else if (strcmp(k, "protocol") == 0 && strcmp(v, "smtp") == 0)
591  options->alproto = ALPROTO_SMTP;
592  else if (strcmp(k, "protocol") == 0 && strcmp(v, "ntp") == 0)
593  options->alproto = ALPROTO_NTP;
594  else if (strcmp(k, "type") == 0 && strcmp(v, "packet") == 0)
595  options->packet = 1;
596  else if (strcmp(k, "filter") == 0 && strcmp(v, "alerts") == 0)
597  options->alerts = 1;
598  else if (strcmp(k, "type") == 0 && strcmp(v, "file") == 0)
599  options->file = 1;
600  else if (strcmp(k, "type") == 0 && strcmp(v, "streaming") == 0)
601  options->streaming = 1;
602  else if (strcmp(k, "type") == 0 && strcmp(v, "flow") == 0)
603  options->flow = 1;
604  else if (strcmp(k, "filter") == 0 && strcmp(v, "tcp") == 0)
605  options->tcp_data = 1;
606  else if (strcmp(k, "type") == 0 && strcmp(v, "stats") == 0)
607  options->stats = 1;
608  else {
609  SCLogError("unknown key and/or value: k='%s', v='%s'", k, v);
610  goto error;
611  }
612  }
613 
614  if (((options->alproto != ALPROTO_UNKNOWN)) + options->packet + options->file > 1) {
615  SCLogError("invalid combination of 'needs' in the script");
616  goto error;
617  }
618 
619  lua_getglobal(luastate, "setup");
620  if (lua_type(luastate, -1) != LUA_TFUNCTION) {
621  SCLogError("no setup function in script");
622  goto error;
623  }
624 
625  lua_getglobal(luastate, "log");
626  if (lua_type(luastate, -1) != LUA_TFUNCTION) {
627  SCLogError("no log function in script");
628  goto error;
629  }
630 
631  lua_getglobal(luastate, "deinit");
632  if (lua_type(luastate, -1) != LUA_TFUNCTION) {
633  SCLogError("no deinit function in script");
634  goto error;
635  }
636 
637  LuaReturnState(luastate);
638  return 0;
639 error:
640  if (luastate)
641  LuaReturnState(luastate);
642  return -1;
643 }
644 
645 /** \brief setup a luastate for use at runtime
646  *
647  * This loads the script, primes it and then runs the 'setup' function.
648  *
649  * \retval state Returns the set up luastate on success, NULL on error
650  */
651 static lua_State *LuaScriptSetup(const char *filename, LogLuaMasterCtx *ctx)
652 {
653  lua_State *luastate = LuaGetState();
654  if (luastate == NULL) {
655  SCLogError("luaL_newstate failed");
656  goto error;
657  }
658 
659  luaL_openlibs(luastate);
660  SCLuaRequirefBuiltIns(luastate);
661  LuaSetPaths(luastate, ctx);
662 
663  int status = luaL_loadfile(luastate, filename);
664  if (status) {
665  SCLogError("couldn't load file: %s", lua_tostring(luastate, -1));
666  goto error;
667  }
668 
669  /* prime the script */
670  if (lua_pcall(luastate, 0, 0, 0) != 0) {
671  SCLogError("couldn't prime file: %s", lua_tostring(luastate, -1));
672  goto error;
673  }
674 
675  lua_getglobal(luastate, "setup");
676 
677  if (lua_pcall(luastate, 0, 0, 0) != 0) {
678  SCLogError("couldn't run script 'setup' function: %s", lua_tostring(luastate, -1));
679  goto error;
680  }
681 
682  SCLogDebug("lua_State %p is set up", luastate);
683  return luastate;
684 error:
685  if (luastate)
686  LuaReturnState(luastate);
687  return NULL;
688 }
689 
690 static void LogLuaSubFree(OutputCtx *oc)
691 {
692  if (oc->data)
693  SCFree(oc->data);
694  SCFree(oc);
695 }
696 
697 /** \brief initialize output for a script instance
698  *
699  * Runs script 'setup' function.
700  */
701 static OutputInitResult OutputLuaLogInitSub(SCConfNode *conf, OutputCtx *parent_ctx)
702 {
703  OutputInitResult result = { NULL, false };
704  if (conf == NULL)
705  return result;
706 
707  LogLuaCtx *lua_ctx = SCCalloc(1, sizeof(LogLuaCtx));
708  if (unlikely(lua_ctx == NULL))
709  return result;
710 
711  OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
712  if (unlikely(output_ctx == NULL)) {
713  SCFree(lua_ctx);
714  return result;
715  }
716 
717  SCMutexInit(&lua_ctx->m, NULL);
718 
719  BUG_ON(parent_ctx == NULL);
720  LogLuaMasterCtx *mc = parent_ctx->data;
721  BUG_ON(mc == NULL);
722 
723  const char *dir = mc->script_dir;
724  char path[PATH_MAX] = "";
725  if (strlen(dir) > 0) {
726  if (PathMerge(path, sizeof(path), dir, conf->val) < 0) {
727  SCLogError("failed to construct lua script path");
728  goto error;
729  }
730  } else {
731  strlcpy(path, conf->val, sizeof(path));
732  }
733  SCLogDebug("script full path %s", path);
734 
735  SCMutexLock(&lua_ctx->m);
736  lua_ctx->luastate = LuaScriptSetup(path, mc);
737  SCMutexUnlock(&lua_ctx->m);
738  if (lua_ctx->luastate == NULL)
739  goto error;
740 
741  /* the ctx owns this state's invocation counter */
742  LuaStateSetInvocationGen(lua_ctx->luastate, &lua_ctx->invocation_gen);
743 
744  SCLogDebug("lua_ctx %p", lua_ctx);
745 
746  output_ctx->data = lua_ctx;
747  output_ctx->DeInit = LogLuaSubFree;
748 
749  result.ctx = output_ctx;
750  result.ok = true;
751  return result;
752 error:
753  SCMutexDestroy(&lua_ctx->m);
754  SCFree(lua_ctx);
755  SCFree(output_ctx);
756  return result;
757 }
758 
759 static void LogLuaMasterFree(OutputCtx *oc)
760 {
761  if (oc->data)
762  SCFree(oc->data);
763 
764  OutputModule *om, *tom;
765  TAILQ_FOREACH_SAFE (om, &oc->submodules, entries, tom) {
766  SCFree(om);
767  }
768  SCFree(oc);
769 }
770 
771 /** \internal
772  * \brief initialize output instance for lua module
773  *
774  * Parses nested script list, primes them to find out what they
775  * inspect, then fills the OutputCtx::submodules list with the
776  * proper Logger function for the data type the script needs.
777  */
778 static OutputInitResult OutputLuaLogInit(SCConfNode *conf)
779 {
780  OutputInitResult result = { NULL, false };
781  const char *dir = SCConfNodeLookupChildValue(conf, "scripts-dir");
782  if (dir == NULL)
783  dir = "";
784 
785  SCConfNode *scripts = SCConfNodeLookupChild(conf, "scripts");
786  if (scripts == NULL) {
787  /* No "outputs" section in the configuration. */
788  SCLogInfo("scripts not defined");
789  return result;
790  }
791 
792  /* global output ctx setup */
793  OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
794  if (unlikely(output_ctx == NULL)) {
795  return result;
796  }
797  output_ctx->DeInit = LogLuaMasterFree;
798  output_ctx->data = SCCalloc(1, sizeof(LogLuaMasterCtx));
799  if (unlikely(output_ctx->data == NULL)) {
800  SCFree(output_ctx);
801  return result;
802  }
803  LogLuaMasterCtx *master_config = output_ctx->data;
804  strlcpy(master_config->script_dir, dir, sizeof(master_config->script_dir));
805 
806  const char *lua_path = SCConfNodeLookupChildValue(conf, "path");
807  if (lua_path && strlen(lua_path) > 0) {
808  strlcpy(master_config->path, lua_path, sizeof(master_config->path));
809  }
810 
811  const char *lua_cpath = SCConfNodeLookupChildValue(conf, "cpath");
812  if (lua_cpath && strlen(lua_cpath) > 0) {
813  strlcpy(master_config->cpath, lua_cpath, sizeof(master_config->cpath));
814  }
815 
816  TAILQ_INIT(&output_ctx->submodules);
817 
818  /* check the enables scripts and set them up as submodules */
819  SCConfNode *script;
820  TAILQ_FOREACH (script, &scripts->head, next) {
821  SCLogInfo("enabling script %s", script->val);
822  LogLuaScriptOptions opts;
823  memset(&opts, 0x00, sizeof(opts));
824 
825  char path[PATH_MAX] = "";
826  snprintf(path, sizeof(path), "%s%s%s", dir, strlen(dir) ? "/" : "", script->val);
827  SCLogDebug("script full path %s", path);
828 
829  int r = LuaScriptInit(path, &opts, master_config);
830  if (r != 0) {
831  SCLogError("couldn't initialize script");
832  goto error;
833  }
834 
835  /* create an OutputModule for this script, based
836  * on it's needs. */
837  OutputModule *om = SCCalloc(1, sizeof(*om));
838  if (om == NULL) {
839  SCLogError("calloc() failed");
840  goto error;
841  }
842 
843  om->name = MODULE_NAME;
844  om->conf_name = script->val;
845  om->InitSubFunc = OutputLuaLogInitSub;
846  om->ThreadInit = LuaLogThreadInit;
847  om->ThreadDeinit = LuaLogThreadDeinit;
848 
849  if (opts.alproto == ALPROTO_HTTP1 && opts.streaming) {
850  om->StreamingLogFunc = LuaStreamingLogger;
852  om->alproto = ALPROTO_HTTP1;
855  } else if (opts.alproto == ALPROTO_HTTP1) {
856  om->TxLogFunc = LuaTxLogger;
857  om->alproto = ALPROTO_HTTP1;
858  om->ts_log_progress = -1;
859  om->tc_log_progress = -1;
861  } else if (opts.alproto == ALPROTO_TLS) {
862  om->TxLogFunc = LuaTxLogger;
863  om->alproto = ALPROTO_TLS;
864  om->TxLogCondition = LuaTlsTxLogCondition;
866  } else if (opts.alproto == ALPROTO_DNS) {
867  om->TxLogFunc = LuaTxLogger;
868  om->alproto = ALPROTO_DNS;
869  om->ts_log_progress = -1;
870  om->tc_log_progress = -1;
873  } else if (opts.alproto == ALPROTO_SSH) {
874  om->TxLogFunc = LuaTxLogger;
875  om->alproto = ALPROTO_SSH;
878  } else if (opts.alproto == ALPROTO_SMTP) {
879  om->TxLogFunc = LuaTxLogger;
880  om->alproto = ALPROTO_SMTP;
881  om->ts_log_progress = -1;
882  om->tc_log_progress = -1;
884  } else if (opts.alproto == ALPROTO_NTP) {
885  om->TxLogFunc = LuaTxLogger;
886  om->alproto = ALPROTO_NTP;
887  om->ts_log_progress = -1;
888  om->tc_log_progress = -1;
890  } else if (opts.packet && opts.alerts) {
891  om->PacketLogFunc = LuaPacketLoggerAlerts;
892  om->PacketConditionFunc = LuaPacketConditionAlerts;
893  } else if (opts.packet && opts.alerts == 0) {
894  om->PacketLogFunc = LuaPacketLogger;
895  om->PacketConditionFunc = LuaPacketCondition;
896  } else if (opts.file) {
897  om->FileLogFunc = LuaFileLogger;
899  } else if (opts.streaming && opts.tcp_data) {
900  om->StreamingLogFunc = LuaStreamingLogger;
902  } else if (opts.flow) {
903  om->FlowLogFunc = LuaFlowLogger;
904  } else if (opts.stats) {
905  om->StatsLogFunc = LuaStatsLogger;
906  } else {
907  SCLogError("failed to setup thread module");
908  SCFree(om);
909  goto error;
910  }
911 
912  TAILQ_INSERT_TAIL(&output_ctx->submodules, om, entries);
913  }
914 
915  result.ctx = output_ctx;
916  result.ok = true;
917  return result;
918 
919 error:
920  if (output_ctx->DeInit)
921  output_ctx->DeInit(output_ctx);
922 
923  int failure_fatal = 0;
924  if (SCConfGetBool("engine.init-failure-fatal", &failure_fatal) != 1) {
925  SCLogDebug("ConfGetBool could not load the value.");
926  }
927  if (failure_fatal) {
928  FatalError("Error during setup of lua output. Details should be "
929  "described in previous error messages. Shutting down...");
930  }
931 
932  return result;
933 }
934 
935 /** \internal
936  * \brief Run the scripts 'deinit' function
937  */
938 static void OutputLuaLogDoDeinit(LogLuaCtx *lua_ctx)
939 {
940  /* called with lua_ctx->m held (LuaLogThreadDeinit): the state is
941  * shared by all threads of the submodule, and the log paths hold
942  * that same mutex while logging, so a NULLed state is never used
943  * and a logging state is never closed underneath a logger */
944  lua_State *luastate = lua_ctx->luastate;
945 
946  /* the context slots name the last callback's objects, which the
947  * engine may have freed by now (the packet pool is destroyed before
948  * the thread deinit): clear them so a handle used from deinit() or
949  * a close-time finalizer fails closed */
950  LuaStateSetPacket(luastate, NULL);
951  LuaStateSetPacketAlert(luastate, NULL);
952  LuaStateSetTX(luastate, NULL, 0);
953  LuaStateSetFlow(luastate, NULL);
954  LuaStateSetFile(luastate, NULL);
955 
956  lua_getglobal(luastate, "deinit");
957  if (lua_type(luastate, -1) == LUA_TFUNCTION) {
958  if (lua_pcall(luastate, 0, 0, 0) != 0) {
959  SCLogError("couldn't run script 'deinit' function: %s", lua_tostring(luastate, -1));
960  lua_pop(luastate, 1);
961  }
962  } else {
963  SCLogError("no deinit function in script");
964  lua_pop(luastate, 1);
965  }
966 
967  /* returned on every path: a deinit failure must not leak the
968  * (unsandboxed) state and its C-side contexts */
969  LuaReturnState(luastate);
970  lua_ctx->luastate = NULL;
971 }
972 
973 /** \internal
974  * \brief Initialize the thread storage for lua
975  *
976  * Currently only stores a pointer to the global LogLuaCtx
977  */
978 static TmEcode LuaLogThreadInit(ThreadVars *t, const void *initdata, void **data)
979 {
980  LogLuaThreadCtx *td = SCCalloc(1, sizeof(*td));
981  if (unlikely(td == NULL))
982  return TM_ECODE_FAILED;
983 
984  if (initdata == NULL) {
985  SCLogDebug("Error getting context for LuaLog. \"initdata\" argument NULL");
986  SCFree(td);
987  return TM_ECODE_FAILED;
988  }
989 
990  LogLuaCtx *lua_ctx = ((OutputCtx *)initdata)->data;
991  SCLogDebug("lua_ctx %p", lua_ctx);
992  td->lua_ctx = lua_ctx;
993  *data = (void *)td;
994  return TM_ECODE_OK;
995 }
996 
997 /** \internal
998  * \brief Deinit the thread storage for lua
999  *
1000  * Calls OutputLuaLogDoDeinit if no-one else already did.
1001  */
1002 static TmEcode LuaLogThreadDeinit(ThreadVars *t, void *data)
1003 {
1004  LogLuaThreadCtx *td = (LogLuaThreadCtx *)data;
1005  if (td == NULL) {
1006  return TM_ECODE_OK;
1007  }
1008 
1009  SCMutexLock(&td->lua_ctx->m);
1010  if (td->lua_ctx->deinit_once == 0) {
1011  OutputLuaLogDoDeinit(td->lua_ctx);
1012  td->lua_ctx->deinit_once = 1;
1013  }
1014  SCMutexUnlock(&td->lua_ctx->m);
1015 
1016  /* clear memory */
1017  memset(td, 0, sizeof(*td));
1018 
1019  SCFree(td);
1020  return TM_ECODE_OK;
1021 }
1022 
1023 void LuaLogRegister(void)
1024 {
1025  /* register as separate module */
1026  OutputRegisterModule(MODULE_NAME, "lua", OutputLuaLogInit);
1027 }
LuaStateSetTX
void LuaStateSetTX(lua_State *luastate, void *txptr, const uint64_t tx_id)
Definition: util-lua.c:248
LogLuaThreadCtx
struct LogLuaThreadCtx_ LogLuaThreadCtx
LuaStateSetPacket
void LuaStateSetPacket(lua_State *luastate, Packet *p)
Definition: util-lua.c:228
OutputModule_::FileLogFunc
SCFileLogger FileLogFunc
Definition: output.h:71
LogLuaMasterCtx_
structure containing global config The OutputLuaLogInitSub which is run per script can access this to...
Definition: output-lua.c:48
AppLayerHtpNeedFileInspection
void AppLayerHtpNeedFileInspection(void)
Sets a flag that informs the HTP app layer that some module in the engine needs the http request file...
Definition: app-layer-htp.c:569
LuaStateSetThreadVars
void LuaStateSetThreadVars(lua_State *luastate, ThreadVars *tv)
Definition: util-lua.c:193
PacketAlert_::s
const struct Signature_ * s
Definition: decode.h:254
STREAMING_TCP_DATA
@ STREAMING_TCP_DATA
Definition: output-streaming.h:36
LogLuaCtx_::invocation_gen
uint64_t invocation_gen
Definition: output-lua.c:66
LogLuaScriptOptions_::file
int file
Definition: output-lua.c:466
app-layer-ssh.h
LuaStateSetInvocationGen
void LuaStateSetInvocationGen(lua_State *luastate, uint64_t *gen)
publish the state's invocation counter (once, at state init)
Definition: util-lua.c:210
LogLuaScriptOptions_::alproto
AppProto alproto
Definition: output-lua.c:463
util-lua-common.h
TAILQ_INIT
#define TAILQ_INIT(head)
Definition: queue.h:262
LuaPushTableKeyValueInt
void LuaPushTableKeyValueInt(lua_State *luastate, const char *key, int value)
Definition: util-lua-common.c:238
ALPROTO_DNS
@ ALPROTO_DNS
Definition: app-layer-protos.h:47
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
ALPROTO_TLS
@ ALPROTO_TLS
Definition: app-layer-protos.h:39
PathMerge
int PathMerge(char *out_buf, size_t buf_size, const char *const dir, const char *const fname)
Definition: util-path.c:75
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
Flow_::proto
uint8_t proto
Definition: flow.h:381
util-lua.h
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:87
LogLuaCtx_
Definition: output-lua.c:59
PacketAlerts_::cnt
uint16_t cnt
Definition: decode.h:289
action-globals.h
LuaGetState
lua_State * LuaGetState(void)
Definition: util-lua.c:56
OutputModule_::name
const char * name
Definition: output.h:58
Flow_
Flow data structure.
Definition: flow.h:359
ctx
struct Thresholds ctx
LogLuaScriptOptions_::tcp_data
int tcp_data
Definition: output-lua.c:468
OutputModule_::ts_log_progress
int ts_log_progress
Definition: output.h:80
TAILQ_FOREACH
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:252
PacketAlerts_::alerts
PacketAlert * alerts
Definition: decode.h:293
SSHTxLogCondition
bool SSHTxLogCondition(ThreadVars *tv, const Packet *p, void *state, void *tx, uint64_t tx_id)
Definition: app-layer-ssh.c:64
OutputModule_::StatsLogFunc
StatsLogger StatsLogFunc
Definition: output.h:75
SCMutexLock
#define SCMutexLock(mut)
Definition: threads-debug.h:117
SCConfGetBool
int SCConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
Definition: conf.c:523
p
Packet * p
Definition: fuzz_dataset.c:30
LuaStateSetFlow
void LuaStateSetFlow(lua_State *luastate, Flow *f)
set a flow pointer in the lua state
Definition: util-lua.c:267
TAILQ_INSERT_TAIL
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:294
util-lua-builtins.h
LogLuaScriptOptions
struct LogLuaScriptOptions_ LogLuaScriptOptions
OutputModule_::InitSubFunc
OutputInitSubFunc InitSubFunc
Definition: output.h:62
SCConfNodeLookupChildValue
const char * SCConfNodeLookupChildValue(const SCConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
Definition: conf.c:877
ALPROTO_SSH
@ ALPROTO_SSH
Definition: app-layer-protos.h:40
StatsRecord_::pvalue
int64_t pvalue
Definition: output-stats.h:36
LogLuaThreadCtx_
Definition: output-lua.c:69
OutputModule_::PacketLogFunc
PacketLogger PacketLogFunc
Definition: output.h:67
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:82
OUTPUT_STREAMING_FLAG_TRANSACTION
#define OUTPUT_STREAMING_FLAG_TRANSACTION
Definition: output-streaming.h:33
OutputModule_::alproto
AppProto alproto
Definition: output.h:76
LogLuaMasterCtx_::path
char path[PATH_MAX]
Lua search path for Lua modules.
Definition: output-lua.c:53
Packet_::alerts
PacketAlerts alerts
Definition: decode.h:639
OutputCtx_::data
void * data
Definition: tm-modules.h:91
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:81
PacketAlert_::tx_id
uint64_t tx_id
Definition: decode.h:255
OutputCtx_
Definition: tm-modules.h:88
PacketAlert_::action
uint8_t action
Definition: decode.h:251
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
lua_State
struct lua_State lua_State
Definition: suricata-common.h:527
LogLuaMasterCtx
struct LogLuaMasterCtx_ LogLuaMasterCtx
structure containing global config The OutputLuaLogInitSub which is run per script can access this to...
OutputModule_::stream_type
enum SCOutputStreamingType stream_type
Definition: output.h:78
app-layer-htp.h
OutputModule_::ThreadInit
ThreadInitFunc ThreadInit
Definition: output.h:64
util-debug.h
LogLuaScriptOptions_
Definition: output-lua.c:462
OutputInitResult_::ctx
OutputCtx * ctx
Definition: output.h:47
OutputModule_::ThreadDeinit
ThreadDeinitFunc ThreadDeinit
Definition: output.h:65
SCAppLayerParserRegisterLogger
void SCAppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:535
Packet_::ts
SCTime_t ts
Definition: decode.h:572
LogLuaScriptOptions_::stats
int stats
Definition: output-lua.c:471
SCMutexUnlock
#define SCMutexUnlock(mut)
Definition: threads-debug.h:120
LuaStateSetFile
void LuaStateSetFile(lua_State *luastate, File *file)
Definition: util-lua.c:301
ALPROTO_SMTP
@ ALPROTO_SMTP
Definition: app-layer-protos.h:38
AppLayerHtpEnableRequestBodyCallback
void AppLayerHtpEnableRequestBodyCallback(void)
Sets a flag that informs the HTP app layer that some module in the engine needs the http request body...
Definition: app-layer-htp.c:542
OutputRegisterModule
void OutputRegisterModule(const char *, const char *, OutputInitFunc)
SCEnter
#define SCEnter(...)
Definition: util-debug.h:284
LogLuaScriptOptions_::packet
int packet
Definition: output-lua.c:464
StatsRecord_::name
const char * name
Definition: output-stats.h:32
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
LogLuaCtx_::luastate
lua_State * luastate
Definition: output-lua.c:61
OutputModule_::StreamingLogFunc
SCStreamingLogger StreamingLogFunc
Definition: output.h:74
LogLuaScriptOptions_::streaming
int streaming
Definition: output-lua.c:467
OutputInitResult_::ok
bool ok
Definition: output.h:48
app-layer-parser.h
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:322
StatsTable_
Definition: output-stats.h:39
StatsRecord_::value
int64_t value
Definition: output-stats.h:35
LogLuaCtx_::m
SCMutex m
Definition: output-lua.c:60
OutputModule_::conf_name
const char * conf_name
Definition: output.h:59
OutputModule_::FlowLogFunc
FlowLogger FlowLogFunc
Definition: output.h:73
ACTION_ALERT
#define ACTION_ALERT
Definition: action-globals.h:29
Packet_
Definition: decode.h:518
TmEcode
TmEcode
Definition: tm-threads-common.h:80
LogLuaScriptOptions_::http_body
int http_body
Definition: output-lua.c:469
AppLayerHtpEnableResponseBodyCallback
void AppLayerHtpEnableResponseBodyCallback(void)
Sets a flag that informs the HTP app layer that some module in the engine needs the http request body...
Definition: app-layer-htp.c:555
LogLuaScriptOptions_::flow
int flow
Definition: output-lua.c:470
SCLuaRequirefBuiltIns
void SCLuaRequirefBuiltIns(lua_State *L)
Register Suricata built-in modules for loading in a non-sandboxed environment.
Definition: util-lua-builtins.c:87
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:232
TAILQ_FOREACH_SAFE
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:329
AppLayerParserGetTx
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
Definition: app-layer-parser.c:1219
SCMutexInit
#define SCMutexInit(mut, mutattrs)
Definition: threads-debug.h:116
StatsTable_::stats
StatsRecord * stats
Definition: output-stats.h:40
util-lua-smtp.h
PacketAlert_::flags
uint8_t flags
Definition: decode.h:252
File_::flags
uint16_t flags
Definition: util-file.h:147
SCConfNodeLookupChild
SCConfNode * SCConfNodeLookupChild(const SCConfNode *node, const char *name)
Lookup a child configuration node by name.
Definition: conf.c:849
File_
Definition: util-file.h:146
LogLuaMasterCtx_::cpath
char cpath[PATH_MAX]
Lua search path for C modules.
Definition: output-lua.c:56
cnt
uint32_t cnt
Definition: tmqh-packetpool.h:7
OutputInitResult_
Definition: output.h:46
Packet_::flow
struct Flow_ * flow
Definition: decode.h:566
OutputModule_::TxLogCondition
TxLoggerCondition TxLogCondition
Definition: output.h:70
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
OUTPUT_STREAMING_FLAG_OPEN
#define OUTPUT_STREAMING_FLAG_OPEN
Definition: output-streaming.h:29
OutputCtx_::DeInit
void(* DeInit)(struct OutputCtx_ *)
Definition: tm-modules.h:94
util-path.h
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition: app-layer-protos.h:36
LuaStateSetPacketAlert
void LuaStateSetPacketAlert(lua_State *luastate, PacketAlert *pa)
Definition: util-lua.c:279
StatsRecord_::tm_name
const char * tm_name
Definition: output-stats.h:34
FatalError
#define FatalError(...)
Definition: util-debug.h:517
SSLV3TxLogReady
bool SSLV3TxLogReady(void *tx)
Definition: app-layer-ssl.c:3038
LuaLogRegister
void LuaLogRegister(void)
Definition: output-lua.c:1023
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:34
OutputModule_::PacketConditionFunc
PacketLogCondition PacketConditionFunc
Definition: output.h:68
FILE_LOGGED
#define FILE_LOGGED
Definition: util-file.h:120
OUTPUT_STREAMING_FLAG_TOSERVER
#define OUTPUT_STREAMING_FLAG_TOSERVER
Definition: output-streaming.h:31
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:274
LuaStateSetDirection
void LuaStateSetDirection(lua_State *luastate, int direction)
Definition: util-lua.c:339
SCFree
#define SCFree(p)
Definition: util-mem.h:61
Flow_::alstate
void * alstate
Definition: flow.h:484
OutputModule_::TxLogFunc
TxLogger TxLogFunc
Definition: output.h:69
OutputModule_::tc_log_progress
int tc_log_progress
Definition: output.h:79
STREAMING_HTTP_BODIES
@ STREAMING_HTTP_BODIES
Definition: output-streaming.h:37
PACKET_ALERT_FLAG_TX
#define PACKET_ALERT_FLAG_TX
Definition: decode.h:274
ALPROTO_UNKNOWN
@ ALPROTO_UNKNOWN
Definition: app-layer-protos.h:29
output-lua.h
LuaPushTableKeyValueBoolean
void LuaPushTableKeyValueBoolean(lua_State *luastate, const char *key, bool value)
Definition: util-lua-common.c:245
OUTPUT_STREAMING_FLAG_CLOSE
#define OUTPUT_STREAMING_FLAG_CLOSE
Definition: output-streaming.h:30
OUTPUT_STREAMING_FLAG_TOCLIENT
#define OUTPUT_STREAMING_FLAG_TOCLIENT
Definition: output-streaming.h:32
LuaPushTableKeyValueLString
void LuaPushTableKeyValueLString(lua_State *luastate, const char *key, const char *value, size_t len)
Push a key plus string value with length to the stack.
Definition: util-lua-common.c:265
PacketAlert_
Definition: decode.h:249
ALPROTO_NTP
@ ALPROTO_NTP
Definition: app-layer-protos.h:52
LogLuaCtx_::deinit_once
int deinit_once
Definition: output-lua.c:62
util-lua-http.h
LogLuaCtx
struct LogLuaCtx_ LogLuaCtx
LogLuaScriptOptions_::alerts
int alerts
Definition: output-lua.c:465
OutputModule_
Definition: output.h:56
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:455
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:288
SCMutexDestroy
#define SCMutexDestroy
Definition: threads-debug.h:121
SCConfNode_
Definition: conf.h:37
LogLuaMasterCtx_::script_dir
char script_dir[PATH_MAX]
Path to script directory.
Definition: output-lua.c:50
SCConfNode_::val
char * val
Definition: conf.h:39
StatsTable_::nstats
uint32_t nstats
Definition: output-stats.h:42
SCMutex
#define SCMutex
Definition: threads-debug.h:114
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:109
app-layer-ssl.h
CreateTimeString
void CreateTimeString(const SCTime_t ts, char *str, size_t size)
Definition: util-time.c:272
LogLuaThreadCtx_::lua_ctx
LogLuaCtx * lua_ctx
Definition: output-lua.c:70
output.h
LuaReturnState
void LuaReturnState(lua_State *s)
Definition: util-lua.c:63
MODULE_NAME
#define MODULE_NAME
Definition: output-lua.c:41
f
Flow f
Definition: fuzz_dataset.c:32