suricata
output-json.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2023 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 Tom DeCanio <td@npulsetech.com>
22  *
23  * Logs detection and monitoring events in JSON format.
24  *
25  */
26 
27 #include "suricata-common.h"
28 #include "flow.h"
29 #include "conf.h"
30 
31 #include "util-debug.h"
32 #include "util-time.h"
33 #include "util-var-name.h"
34 #include "util-macset.h"
35 
36 #include "util-unittest.h"
37 #include "util-unittest-helper.h"
38 
39 #include "detect-engine.h"
41 #include "util-syslog.h"
42 
43 /* Internal output plugins */
44 #include "output-eve-syslog.h"
45 #include "output-eve-null.h"
46 
47 #include "output.h"
48 #include "output-json.h"
49 
50 #include "util-byte.h"
51 #include "util-print.h"
52 #include "util-proto-name.h"
53 #include "util-optimize.h"
54 #include "util-buffer.h"
55 #include "util-logopenfile.h"
56 #include "util-log-redis.h"
57 #include "util-device-private.h"
58 #include "util-validate.h"
59 
60 #include "flow-var.h"
61 #include "flow-bit.h"
62 #include "flow-storage.h"
63 
65 
66 #define DEFAULT_LOG_FILENAME "eve.json"
67 #define MODULE_NAME "OutputJSON"
68 
69 #define MAX_JSON_SIZE 2048
70 
71 static void OutputJsonDeInitCtx(OutputCtx *);
72 static void CreateEveCommunityFlowId(SCJsonBuilder *js, const Flow *f, const uint16_t seed);
73 static int CreateJSONEther(
74  SCJsonBuilder *parent, const Packet *p, const Flow *f, enum SCOutputJsonLogDirection dir);
75 
76 static const char *TRAFFIC_ID_PREFIX = "traffic/id/";
77 static const char *TRAFFIC_LABEL_PREFIX = "traffic/label/";
78 static size_t traffic_id_prefix_len = 0;
79 static size_t traffic_label_prefix_len = 0;
80 
82 
83 void OutputJsonRegister (void)
84 {
86 
87  traffic_id_prefix_len = strlen(TRAFFIC_ID_PREFIX);
88  traffic_label_prefix_len = strlen(TRAFFIC_LABEL_PREFIX);
89 
90  // Register output file types that use the new eve filetype registration
91  // API.
94 }
95 
96 json_t *SCJsonString(const char *val)
97 {
98  if (val == NULL){
99  return NULL;
100  }
101  json_t * retval = json_string(val);
102  char retbuf[MAX_JSON_SIZE] = {0};
103  if (retval == NULL) {
104  uint32_t u = 0;
105  uint32_t offset = 0;
106  for (u = 0; u < strlen(val); u++) {
107  if (isprint(val[u])) {
108  PrintBufferData(retbuf, &offset, MAX_JSON_SIZE-1, "%c",
109  val[u]);
110  } else {
112  "\\x%02X", val[u]);
113  }
114  }
115  retbuf[offset] = '\0';
116  retval = json_string(retbuf);
117  }
118  return retval;
119 }
120 
121 /* Default Sensor ID value */
122 static int64_t sensor_id = -1; /* -1 = not defined */
123 
124 void EveFileInfo(SCJsonBuilder *jb, const File *ff, const uint64_t tx_id, const uint16_t flags)
125 {
126  SCJbSetStringFromBytes(jb, "filename", ff->name, ff->name_len);
127 
128  if (ff->sid_cnt > 0) {
129  SCJbOpenArray(jb, "sid");
130  for (uint32_t i = 0; ff->sid != NULL && i < ff->sid_cnt; i++) {
131  SCJbAppendUint(jb, ff->sid[i]);
132  }
133  SCJbClose(jb);
134  }
135 
136 #ifdef HAVE_MAGIC
137  if (ff->magic)
138  SCJbSetString(jb, "magic", (char *)ff->magic);
139 #endif
140  SCJbSetBool(jb, "gaps", ff->flags & FILE_HAS_GAPS);
141  switch (ff->state) {
142  case FILE_STATE_CLOSED:
143  JB_SET_STRING(jb, "state", "CLOSED");
144  if (ff->flags & FILE_MD5) {
145  SCJbSetHex(jb, "md5", (uint8_t *)ff->md5, (uint32_t)sizeof(ff->md5));
146  }
147  if (ff->flags & FILE_SHA1) {
148  SCJbSetHex(jb, "sha1", (uint8_t *)ff->sha1, (uint32_t)sizeof(ff->sha1));
149  }
150  break;
152  JB_SET_STRING(jb, "state", "TRUNCATED");
153  break;
154  case FILE_STATE_ERROR:
155  JB_SET_STRING(jb, "state", "ERROR");
156  break;
157  default:
158  JB_SET_STRING(jb, "state", "UNKNOWN");
159  break;
160  }
161 
162  if (ff->flags & FILE_SHA256) {
163  SCJbSetHex(jb, "sha256", (uint8_t *)ff->sha256, (uint32_t)sizeof(ff->sha256));
164  }
165 
166  if (flags & FILE_STORED) {
167  JB_SET_TRUE(jb, "stored");
168  SCJbSetUint(jb, "file_id", ff->file_store_id);
169  } else {
170  JB_SET_FALSE(jb, "stored");
171  if (flags & FILE_STORE) {
172  JB_SET_TRUE(jb, "storing");
173  }
174  }
175 
176  SCJbSetUint(jb, "size", FileTrackedSize(ff));
177  if (ff->end > 0) {
178  SCJbSetUint(jb, "start", ff->start);
179  SCJbSetUint(jb, "end", ff->end);
180  }
181  SCJbSetUint(jb, "tx_id", tx_id);
182 }
183 
184 static void EveAddPacketVars(const Packet *p, SCJsonBuilder *js_vars)
185 {
186  if (p == NULL || p->pktvar == NULL) {
187  return;
188  }
189  PktVar *pv = p->pktvar;
190  bool open = false;
191  while (pv != NULL) {
192  if (pv->key || pv->id > 0) {
193  if (!open) {
194  SCJbOpenArray(js_vars, "pktvars");
195  open = true;
196  }
197  SCJbStartObject(js_vars);
198 
199  if (pv->key != NULL) {
200  uint32_t offset = 0;
201  DEBUG_VALIDATE_BUG_ON(pv->key_len > UINT16_MAX);
202  uint8_t keybuf[pv->key_len + 1];
203  PrintStringsToBuffer(keybuf, &offset, pv->key_len + 1, pv->key, pv->key_len);
204  SCJbSetPrintAsciiString(js_vars, (char *)keybuf, pv->value, pv->value_len);
205  } else {
206  const char *varname = VarNameStoreLookupById(pv->id, VAR_TYPE_PKT_VAR);
207  SCJbSetPrintAsciiString(js_vars, varname, pv->value, pv->value_len);
208  }
209  SCJbClose(js_vars);
210  }
211  pv = pv->next;
212  }
213  if (open) {
214  SCJbClose(js_vars);
215  }
216 }
217 
218 /**
219  * \brief Check if string s has prefix prefix.
220  *
221  * \retval true if string has prefix
222  * \retval false if string does not have prefix
223  *
224  * TODO: Move to file with other string handling functions.
225  */
226 static bool SCStringHasPrefix(const char *s, const char *prefix)
227 {
228  return strncmp(s, prefix, strlen(prefix)) == 0;
229 }
230 
231 static void EveAddFlowVars(const Flow *f, SCJsonBuilder *js_root, SCJsonBuilder **js_traffic)
232 {
233  if (f == NULL || f->flowvar == NULL) {
234  return;
235  }
236  SCJsonBuilder *js_flowvars = NULL;
237  SCJsonBuilder *js_traffic_id = NULL;
238  SCJsonBuilder *js_traffic_label = NULL;
239  SCJsonBuilder *js_flowints = NULL;
240  SCJsonBuilder *js_entropyvals = NULL;
241  SCJsonBuilder *js_flowbits = NULL;
242  GenericVar *gv = f->flowvar;
243  while (gv != NULL) {
244  if (gv->type == DETECT_FLOWVAR || gv->type == DETECT_FLOWINT) {
245  FlowVar *fv = (FlowVar *)gv;
246  if (fv->datatype == FLOWVAR_TYPE_STR && fv->key == NULL) {
247  const char *varname = VarNameStoreLookupById(fv->idx,
249  if (varname) {
250  if (js_flowvars == NULL) {
251  js_flowvars = SCJbNewArray();
252  if (js_flowvars == NULL)
253  break;
254  }
255 
256  SCJbStartObject(js_flowvars);
257  SCJbSetPrintAsciiString(
258  js_flowvars, varname, fv->data.fv_str.value, fv->data.fv_str.value_len);
259  SCJbClose(js_flowvars);
260  }
261  } else if (fv->datatype == FLOWVAR_TYPE_STR && fv->key != NULL) {
262  if (js_flowvars == NULL) {
263  js_flowvars = SCJbNewArray();
264  if (js_flowvars == NULL)
265  break;
266  }
267 
268  // fv->keylen is uint16
269  uint8_t keybuf[fv->keylen + 1];
270  uint32_t offset = 0;
271  PrintStringsToBuffer(keybuf, &offset, fv->keylen + 1, fv->key, fv->keylen);
272 
273  SCJbStartObject(js_flowvars);
274  SCJbSetPrintAsciiString(js_flowvars, (const char *)keybuf, fv->data.fv_str.value,
275  fv->data.fv_str.value_len);
276  SCJbClose(js_flowvars);
277  } else if (fv->datatype == FLOWVAR_TYPE_FLOAT) {
278  const char *varname = VarNameStoreLookupById(fv->idx, VAR_TYPE_FLOW_FLOAT);
279  if (varname) {
280  if (js_entropyvals == NULL) {
281  js_entropyvals = SCJbNewObject();
282  if (js_entropyvals == NULL)
283  break;
284  }
285  SCJbSetFloat(js_entropyvals, varname, fv->data.fv_float.value);
286  }
287 
288  } else if (fv->datatype == FLOWVAR_TYPE_INT) {
289  const char *varname = VarNameStoreLookupById(fv->idx,
291  if (varname) {
292  if (js_flowints == NULL) {
293  js_flowints = SCJbNewObject();
294  if (js_flowints == NULL)
295  break;
296  }
297  SCJbSetUint(js_flowints, varname, fv->data.fv_int.value);
298  }
299  }
300  } else if (gv->type == DETECT_FLOWBITS) {
301  FlowBit *fb = (FlowBit *)gv;
302  const char *varname = VarNameStoreLookupById(fb->idx,
304  if (varname) {
305  if (SCStringHasPrefix(varname, TRAFFIC_ID_PREFIX)) {
306  if (js_traffic_id == NULL) {
307  js_traffic_id = SCJbNewArray();
308  if (unlikely(js_traffic_id == NULL)) {
309  break;
310  }
311  }
312  SCJbAppendString(js_traffic_id, &varname[traffic_id_prefix_len]);
313  } else if (SCStringHasPrefix(varname, TRAFFIC_LABEL_PREFIX)) {
314  if (js_traffic_label == NULL) {
315  js_traffic_label = SCJbNewArray();
316  if (unlikely(js_traffic_label == NULL)) {
317  break;
318  }
319  }
320  SCJbAppendString(js_traffic_label, &varname[traffic_label_prefix_len]);
321  } else {
322  if (js_flowbits == NULL) {
323  js_flowbits = SCJbNewArray();
324  if (unlikely(js_flowbits == NULL))
325  break;
326  }
327  SCJbAppendString(js_flowbits, varname);
328  }
329  }
330  }
331  gv = gv->next;
332  }
333  if (js_flowbits) {
334  SCJbClose(js_flowbits);
335  SCJbSetObject(js_root, "flowbits", js_flowbits);
336  SCJbFree(js_flowbits);
337  }
338  if (js_flowints) {
339  SCJbClose(js_flowints);
340  SCJbSetObject(js_root, "flowints", js_flowints);
341  SCJbFree(js_flowints);
342  }
343  if (js_entropyvals) {
344  SCJbClose(js_entropyvals);
345  SCJbSetObject(js_root, "entropy", js_entropyvals);
346  SCJbFree(js_entropyvals);
347  }
348  if (js_flowvars) {
349  SCJbClose(js_flowvars);
350  SCJbSetObject(js_root, "flowvars", js_flowvars);
351  SCJbFree(js_flowvars);
352  }
353 
354  if (js_traffic_id != NULL || js_traffic_label != NULL) {
355  *js_traffic = SCJbNewObject();
356  if (likely(*js_traffic != NULL)) {
357  if (js_traffic_id != NULL) {
358  SCJbClose(js_traffic_id);
359  SCJbSetObject(*js_traffic, "id", js_traffic_id);
360  SCJbFree(js_traffic_id);
361  }
362  if (js_traffic_label != NULL) {
363  SCJbClose(js_traffic_label);
364  SCJbSetObject(*js_traffic, "label", js_traffic_label);
365  SCJbFree(js_traffic_label);
366  }
367  SCJbClose(*js_traffic);
368  }
369  }
370 }
371 
372 void EveAddMetadata(const Packet *p, const Flow *f, SCJsonBuilder *js)
373 {
374  if ((p && p->pktvar) || (f && f->flowvar)) {
375  SCJsonBuilder *js_vars = SCJbNewObject();
376  if (js_vars) {
377  if (f && f->flowvar) {
378  SCJsonBuilder *js_traffic = NULL;
379  EveAddFlowVars(f, js_vars, &js_traffic);
380  if (js_traffic != NULL) {
381  SCJbSetObject(js, "traffic", js_traffic);
382  SCJbFree(js_traffic);
383  }
384  }
385  if (p && p->pktvar) {
386  EveAddPacketVars(p, js_vars);
387  }
388  SCJbClose(js_vars);
389  SCJbSetObject(js, "metadata", js_vars);
390  SCJbFree(js_vars);
391  }
392  }
393 }
394 
395 void EveAddCommonOptions(const OutputJsonCommonSettings *cfg, const Packet *p, const Flow *f,
396  SCJsonBuilder *js, enum SCOutputJsonLogDirection dir)
397 {
398  if (cfg->include_suricata_version) {
399  SCJbSetString(js, "suricata_version", PROG_VER);
400  }
401  if (cfg->include_metadata) {
402  EveAddMetadata(p, f, js);
403  }
404  if (cfg->include_ethernet) {
405  CreateJSONEther(js, p, f, dir);
406  }
407  if (cfg->include_community_id && f != NULL) {
408  CreateEveCommunityFlowId(js, f, cfg->community_id_seed);
409  }
410  if (f != NULL && f->tenant_id > 0) {
411  SCJbSetUint(js, "tenant_id", f->tenant_id);
412  }
413 }
414 
415 /**
416  * \brief Jsonify a packet
417  *
418  * \param p Packet
419  * \param js JSON object
420  * \param max_length If non-zero, restricts the number of packet data bytes handled.
421  */
422 void EvePacket(const Packet *p, SCJsonBuilder *js, uint32_t max_length)
423 {
424  uint32_t max_len = max_length == 0 ? GET_PKT_LEN(p) : max_length;
425  SCJbSetBase64(js, "packet", GET_PKT_DATA(p), max_len);
426 
427  if (!SCJbOpenObject(js, "packet_info")) {
428  return;
429  }
430  if (!SCJbSetUint(js, "linktype", p->datalink)) {
431  SCJbClose(js);
432  return;
433  }
434 
435  const char *dl_name = DatalinkValueToName(p->datalink);
436 
437  // Intentionally ignore the return value from SCJbSetString and proceed
438  // so the jb object is closed
439  (void)SCJbSetString(js, "linktype_name", dl_name == NULL ? "n/a" : dl_name);
440 
441  SCJbClose(js);
442 }
443 
444 /** \brief jsonify tcp flags field
445  * Only add 'true' fields in an attempt to keep things reasonably compact.
446  */
447 void EveTcpFlags(const uint8_t flags, SCJsonBuilder *js)
448 {
449  if (flags & TH_SYN)
450  JB_SET_TRUE(js, "syn");
451  if (flags & TH_FIN)
452  JB_SET_TRUE(js, "fin");
453  if (flags & TH_RST)
454  JB_SET_TRUE(js, "rst");
455  if (flags & TH_PUSH)
456  JB_SET_TRUE(js, "psh");
457  if (flags & TH_ACK)
458  JB_SET_TRUE(js, "ack");
459  if (flags & TH_URG)
460  JB_SET_TRUE(js, "urg");
461  if (flags & TH_ECN)
462  JB_SET_TRUE(js, "ecn");
463  if (flags & TH_CWR)
464  JB_SET_TRUE(js, "cwr");
465 }
466 
469 {
470  Port sp, dp;
471 
472  const void *src_ip = NULL;
473  const void *dst_ip = NULL;
474 
475  switch (dir) {
476  case LOG_DIR_PACKET:
477  if (PacketIsIPv4(p)) {
478  src_ip = GET_IPV4_SRC_ADDR_PTR(p);
479  dst_ip = GET_IPV4_DST_ADDR_PTR(p);
480  } else if (PacketIsIPv6(p)) {
481  src_ip = GET_IPV6_SRC_ADDR(p);
482  dst_ip = GET_IPV6_DST_ADDR(p);
483  } else {
484  /* Not an IP packet so don't do anything */
485  return;
486  }
487  sp = p->sp;
488  dp = p->dp;
489  break;
490  case LOG_DIR_FLOW:
492  if ((PKT_IS_TOSERVER(p))) {
493  if (PacketIsIPv4(p)) {
494  src_ip = GET_IPV4_SRC_ADDR_PTR(p);
495  dst_ip = GET_IPV4_DST_ADDR_PTR(p);
496  } else if (PacketIsIPv6(p)) {
497  src_ip = GET_IPV6_SRC_ADDR(p);
498  dst_ip = GET_IPV6_DST_ADDR(p);
499  }
500  sp = p->sp;
501  dp = p->dp;
502  } else {
503  if (PacketIsIPv4(p)) {
504  src_ip = GET_IPV4_DST_ADDR_PTR(p);
505  dst_ip = GET_IPV4_SRC_ADDR_PTR(p);
506  } else if (PacketIsIPv6(p)) {
507  src_ip = GET_IPV6_DST_ADDR(p);
508  dst_ip = GET_IPV6_SRC_ADDR(p);
509  }
510  sp = p->dp;
511  dp = p->sp;
512  }
513  break;
515  if ((PKT_IS_TOCLIENT(p))) {
516  if (PacketIsIPv4(p)) {
517  src_ip = GET_IPV4_SRC_ADDR_PTR(p);
518  dst_ip = GET_IPV4_DST_ADDR_PTR(p);
519  } else if (PacketIsIPv6(p)) {
520  src_ip = GET_IPV6_SRC_ADDR(p);
521  dst_ip = GET_IPV6_DST_ADDR(p);
522  }
523  sp = p->sp;
524  dp = p->dp;
525  } else {
526  if (PacketIsIPv4(p)) {
527  src_ip = GET_IPV4_DST_ADDR_PTR(p);
528  dst_ip = GET_IPV4_SRC_ADDR_PTR(p);
529  } else if (PacketIsIPv6(p)) {
530  src_ip = GET_IPV6_DST_ADDR(p);
531  dst_ip = GET_IPV6_SRC_ADDR(p);
532  }
533  sp = p->dp;
534  dp = p->sp;
535  }
536  break;
537  default:
539  return;
540  }
541 
542  if (PacketIsIPv4(p)) {
543  PrintInet(AF_INET, (const void *)src_ip, addr->src_ip, JSON_ADDR_LEN);
544  PrintInet(AF_INET, (const void *)dst_ip, addr->dst_ip, JSON_ADDR_LEN);
545  } else if (PacketIsIPv6(p)) {
546  PrintInetIPv6((const void *)src_ip, addr->src_ip, sizeof(addr->src_ip), cfg->compress_ipv6);
547  PrintInetIPv6((const void *)dst_ip, addr->dst_ip, sizeof(addr->dst_ip), cfg->compress_ipv6);
548  }
549 
550  switch (p->proto) {
551  case IPPROTO_UDP:
552  case IPPROTO_TCP:
553  case IPPROTO_SCTP:
554  addr->sp = sp;
555  addr->dp = dp;
556  addr->log_port = true;
557  break;
558  default:
559  addr->log_port = false;
560  break;
561  }
562 
563  if (SCProtoNameValid(PacketGetIPProto(p))) {
564  strlcpy(addr->proto, known_proto[PacketGetIPProto(p)], sizeof(addr->proto));
565  } else {
566  snprintf(addr->proto, sizeof(addr->proto), "%" PRIu32, PacketGetIPProto(p));
567  }
568 }
569 
570 #define COMMUNITY_ID_BUF_SIZE 64
571 
572 static bool CalculateCommunityFlowIdv4(const Flow *f,
573  const uint16_t seed, unsigned char *base64buf)
574 {
575  struct {
576  uint16_t seed;
577  uint32_t src;
578  uint32_t dst;
579  uint8_t proto;
580  uint8_t pad0;
581  uint16_t sp;
582  uint16_t dp;
583  } __attribute__((__packed__)) ipv4;
584 
585  uint32_t src = f->src.addr_data32[0];
586  uint32_t dst = f->dst.addr_data32[0];
587  uint16_t sp = f->sp;
588  if (f->proto == IPPROTO_ICMP)
589  sp = f->icmp_s.type;
590  sp = htons(sp);
591  uint16_t dp = f->dp;
592  if (f->proto == IPPROTO_ICMP)
593  dp = f->icmp_d.type;
594  dp = htons(dp);
595 
596  ipv4.seed = htons(seed);
597  if (ntohl(src) < ntohl(dst) || (src == dst && ntohs(sp) < ntohs(dp))) {
598  ipv4.src = src;
599  ipv4.dst = dst;
600  ipv4.sp = sp;
601  ipv4.dp = dp;
602  } else {
603  ipv4.src = dst;
604  ipv4.dst = src;
605  ipv4.sp = dp;
606  ipv4.dp = sp;
607  }
608  ipv4.proto = f->proto;
609  ipv4.pad0 = 0;
610 
611  uint8_t hash[20];
612  if (SCSha1HashBuffer((const uint8_t *)&ipv4, sizeof(ipv4), hash, sizeof(hash)) == 1) {
613  strlcpy((char *)base64buf, "1:", COMMUNITY_ID_BUF_SIZE);
614  unsigned long out_len = COMMUNITY_ID_BUF_SIZE - 2;
615  if (SCBase64Encode(hash, sizeof(hash), base64buf + 2, &out_len) == SC_BASE64_OK) {
616  return true;
617  }
618  }
619  return false;
620 }
621 
622 static bool CalculateCommunityFlowIdv6(const Flow *f,
623  const uint16_t seed, unsigned char *base64buf)
624 {
625  struct {
626  uint16_t seed;
627  uint32_t src[4];
628  uint32_t dst[4];
629  uint8_t proto;
630  uint8_t pad0;
631  uint16_t sp;
632  uint16_t dp;
633  } __attribute__((__packed__)) ipv6;
634 
635  uint16_t sp = f->sp;
636  if (f->proto == IPPROTO_ICMPV6)
637  sp = f->icmp_s.type;
638  sp = htons(sp);
639  uint16_t dp = f->dp;
640  if (f->proto == IPPROTO_ICMPV6)
641  dp = f->icmp_d.type;
642  dp = htons(dp);
643 
644  ipv6.seed = htons(seed);
645  int cmp_r = memcmp(&f->src, &f->dst, sizeof(f->src));
646  if ((cmp_r < 0) || (cmp_r == 0 && ntohs(sp) < ntohs(dp))) {
647  memcpy(&ipv6.src, &f->src.addr_data32, 16);
648  memcpy(&ipv6.dst, &f->dst.addr_data32, 16);
649  ipv6.sp = sp;
650  ipv6.dp = dp;
651  } else {
652  memcpy(&ipv6.src, &f->dst.addr_data32, 16);
653  memcpy(&ipv6.dst, &f->src.addr_data32, 16);
654  ipv6.sp = dp;
655  ipv6.dp = sp;
656  }
657  ipv6.proto = f->proto;
658  ipv6.pad0 = 0;
659 
660  uint8_t hash[20];
661  if (SCSha1HashBuffer((const uint8_t *)&ipv6, sizeof(ipv6), hash, sizeof(hash)) == 1) {
662  strlcpy((char *)base64buf, "1:", COMMUNITY_ID_BUF_SIZE);
663  unsigned long out_len = COMMUNITY_ID_BUF_SIZE - 2;
664  if (SCBase64Encode(hash, sizeof(hash), base64buf + 2, &out_len) == SC_BASE64_OK) {
665  return true;
666  }
667  }
668  return false;
669 }
670 
671 static void CreateEveCommunityFlowId(SCJsonBuilder *js, const Flow *f, const uint16_t seed)
672 {
673  unsigned char buf[COMMUNITY_ID_BUF_SIZE];
674  if (f->flags & FLOW_IPV4) {
675  if (CalculateCommunityFlowIdv4(f, seed, buf)) {
676  SCJbSetString(js, "community_id", (const char *)buf);
677  }
678  } else if (f->flags & FLOW_IPV6) {
679  if (CalculateCommunityFlowIdv6(f, seed, buf)) {
680  SCJbSetString(js, "community_id", (const char *)buf);
681  }
682  }
683 }
684 
685 void CreateEveFlowId(SCJsonBuilder *js, const Flow *f)
686 {
687  if (f == NULL) {
688  return;
689  }
690  uint64_t flow_id = FlowGetId(f);
691  SCJbSetUint(js, "flow_id", flow_id);
692  if (f->parent_id) {
693  SCJbSetUint(js, "parent_id", f->parent_id);
694  }
695 }
696 
697 void JSONFormatAndAddMACAddr(SCJsonBuilder *js, const char *key, const uint8_t *val, bool is_array)
698 {
699  char eth_addr[19];
700  (void) snprintf(eth_addr, 19, "%02x:%02x:%02x:%02x:%02x:%02x",
701  val[0], val[1], val[2], val[3], val[4], val[5]);
702  if (is_array) {
703  SCJbAppendString(js, eth_addr);
704  } else {
705  SCJbSetString(js, key, eth_addr);
706  }
707 }
708 
709 /* only required to traverse the MAC address set */
710 typedef struct JSONMACAddrInfo {
711  SCJsonBuilder *src, *dst;
713 
714 static int MacSetIterateToJSON(uint8_t *val, MacSetSide side, void *data)
715 {
716  JSONMACAddrInfo *info = (JSONMACAddrInfo*) data;
717  if (side == MAC_SET_DST) {
718  JSONFormatAndAddMACAddr(info->dst, NULL, val, true);
719  } else {
720  JSONFormatAndAddMACAddr(info->src, NULL, val, true);
721  }
722  return 0;
723 }
724 
725 static int CreateJSONEther(
726  SCJsonBuilder *js, const Packet *p, const Flow *f, enum SCOutputJsonLogDirection dir)
727 {
728  if (p != NULL) {
729  /* this is a packet context, so we need to add scalar fields */
730  if (PacketIsEthernet(p)) {
731  const EthernetHdr *ethh = PacketGetEthernet(p);
732  SCJbOpenObject(js, "ether");
733  SCJbSetUint(js, "ether_type", SCNtohs(ethh->eth_type));
734  const uint8_t *src;
735  const uint8_t *dst;
736  switch (dir) {
738  // fallthrough
739  case LOG_DIR_FLOW:
740  if (PKT_IS_TOCLIENT(p)) {
741  src = ethh->eth_dst;
742  dst = ethh->eth_src;
743  } else {
744  src = ethh->eth_src;
745  dst = ethh->eth_dst;
746  }
747  break;
749  if (PKT_IS_TOSERVER(p)) {
750  src = ethh->eth_dst;
751  dst = ethh->eth_src;
752  } else {
753  src = ethh->eth_src;
754  dst = ethh->eth_dst;
755  }
756  break;
757  case LOG_DIR_PACKET:
758  default:
759  src = ethh->eth_src;
760  dst = ethh->eth_dst;
761  break;
762  }
763  JSONFormatAndAddMACAddr(js, "src_mac", src, false);
764  JSONFormatAndAddMACAddr(js, "dest_mac", dst, false);
765  SCJbClose(js);
766  } else if (f != NULL) {
767  /* When pseudopackets do not have associated ethernet metadata,
768  use the first set of mac addresses stored with their flow.
769  The first set of macs should come from the flow's first packet,
770  providing the most fitting representation of the event's ethernet. */
772  if (ms != NULL && MacSetSize(ms) > 0) {
773  uint8_t *src = MacSetGetFirst(ms, MAC_SET_SRC);
774  uint8_t *dst = MacSetGetFirst(ms, MAC_SET_DST);
775  if (dst != NULL && src != NULL) {
776  SCJbOpenObject(js, "ether");
777  JSONFormatAndAddMACAddr(js, "src_mac", src, false);
778  JSONFormatAndAddMACAddr(js, "dest_mac", dst, false);
779  SCJbClose(js);
780  }
781  }
782  }
783  } else if (f != NULL) {
784  /* we are creating an ether object in a flow context, so we need to
785  append to arrays */
787  if (ms != NULL && MacSetSize(ms) > 0) {
788  SCJbOpenObject(js, "ether");
789  JSONMACAddrInfo info;
790  info.dst = SCJbNewArray();
791  info.src = SCJbNewArray();
792  int ret = MacSetForEach(ms, MacSetIterateToJSON, &info);
793  if (unlikely(ret != 0)) {
794  /* should not happen, JSONFlowAppendMACAddrs is sane */
795  SCJbFree(info.dst);
796  SCJbFree(info.src);
797  SCJbClose(js);
798  return ret;
799  }
800  SCJbClose(info.dst);
801  SCJbClose(info.src);
802  /* case is handling netflow too so may need to revert */
803  if (dir == LOG_DIR_FLOW_TOCLIENT) {
804  SCJbSetObject(js, "dest_macs", info.src);
805  SCJbSetObject(js, "src_macs", info.dst);
806  } else {
808  SCJbSetObject(js, "dest_macs", info.dst);
809  SCJbSetObject(js, "src_macs", info.src);
810  }
811  SCJbFree(info.dst);
812  SCJbFree(info.src);
813  SCJbClose(js);
814  }
815  }
816  return 0;
817 }
818 
819 SCJsonBuilder *CreateEveHeader(const Packet *p, enum SCOutputJsonLogDirection dir,
820  const char *event_type, JsonAddrInfo *addr, OutputJsonCtx *eve_ctx)
821 {
822  char timebuf[64];
823  const Flow *f = (const Flow *)p->flow;
824 
825  SCJsonBuilder *js = SCJbNewObject();
826  if (unlikely(js == NULL)) {
827  return NULL;
828  }
829 
830  CreateIsoTimeString(p->ts, timebuf, sizeof(timebuf));
831 
832  SCJbSetString(js, "timestamp", timebuf);
833 
834  CreateEveFlowId(js, f);
835 
836  /* sensor id */
837  if (sensor_id >= 0) {
838  SCJbSetUint(js, "sensor_id", sensor_id);
839  }
840 
841  /* input interface */
843  if (dev) {
844  SCJbSetString(js, "in_iface", dev->dev);
845  }
846 
847  /* pcap_cnt */
848  uint64_t pcap_cnt = PcapPacketCntGet(p);
849  if (pcap_cnt != 0) {
850  SCJbSetUint(js, "pcap_cnt", pcap_cnt);
851  }
852 
853  if (event_type) {
854  SCJbSetString(js, "event_type", event_type);
855  }
856 
857  /* vlan */
858  if (p->vlan_idx > 0) {
859  SCJbOpenArray(js, "vlan");
860  SCJbAppendUint(js, p->vlan_id[0]);
861  if (p->vlan_idx > 1) {
862  SCJbAppendUint(js, p->vlan_id[1]);
863  }
864  if (p->vlan_idx > 2) {
865  SCJbAppendUint(js, p->vlan_id[2]);
866  }
867  SCJbClose(js);
868  }
869 
870  /* 5-tuple */
871  JsonAddrInfo addr_info = json_addr_info_zero;
872  if (addr == NULL) {
873  JsonAddrInfoInit(p, dir, &addr_info, &eve_ctx->cfg);
874  addr = &addr_info;
875  }
876  if (addr->src_ip[0] != '\0') {
877  SCJbSetString(js, "src_ip", addr->src_ip);
878  }
879  if (addr->log_port) {
880  SCJbSetUint(js, "src_port", addr->sp);
881  }
882  if (addr->dst_ip[0] != '\0') {
883  SCJbSetString(js, "dest_ip", addr->dst_ip);
884  }
885  if (addr->log_port) {
886  SCJbSetUint(js, "dest_port", addr->dp);
887  }
888  if (addr->proto[0] != '\0') {
889  SCJbSetString(js, "proto", addr->proto);
890  }
891 
892  /* ip version */
893  if (PacketIsIPv4(p)) {
894  SCJbSetUint(js, "ip_v", 4);
895  } else if (PacketIsIPv6(p)) {
896  SCJbSetUint(js, "ip_v", 6);
897  }
898 
899  /* icmp */
900  switch (p->proto) {
901  case IPPROTO_ICMP:
902  if (PacketIsICMPv4(p)) {
903  SCJbSetUint(js, "icmp_type", p->icmp_s.type);
904  SCJbSetUint(js, "icmp_code", p->icmp_s.code);
905  }
906  break;
907  case IPPROTO_ICMPV6:
908  if (PacketIsICMPv6(p)) {
909  SCJbSetUint(js, "icmp_type", PacketGetICMPv6(p)->type);
910  SCJbSetUint(js, "icmp_code", PacketGetICMPv6(p)->code);
911  }
912  break;
913  case IPPROTO_IGMP:
914  if (PacketIsIGMP(p)) {
915  SCLogDebug("rgmp %s", BOOL2STR(p->l4.vars.igmp.rgmp));
916  if (!p->l4.vars.igmp.rgmp) {
917  SCJbOpenObject(js, "igmp");
918  SCJbSetUint(js, "type", PacketGetIGMP(p)->type);
919  SCJbSetUint(js, "version", p->l4.vars.igmp.version);
920  SCJbClose(js);
921  } else {
922  SCJbOpenObject(js, "rgmp");
923  SCJbSetUint(js, "type", PacketGetIGMP(p)->type);
924  SCJbClose(js);
925  }
926  }
927  break;
928  case IPPROTO_SCTP:
929  if (PacketIsSCTP(p)) {
930  SCJbOpenObject(js, "sctp");
931  SCJbSetUint(js, "vtag", SCTP_GET_RAW_VTAG(PacketGetSCTP(p)));
932  SCJbSetUint(js, "chunk_cnt", p->l4.vars.sctp.chunk_cnt);
933  const uint8_t cnt = p->l4.vars.sctp.tracked_chunk_cnt;
934  SCJbOpenArray(js, "chunk_types");
935  for (uint8_t i = 0; i < cnt; i++) {
936  const char *name = SCSctpChunkTypeToString(p->l4.vars.sctp.chunk_types[i]);
937  if (name) {
938  SCJbAppendString(js, name);
939  } else {
940  char unknown[16];
941  snprintf(unknown, sizeof(unknown), "unknown(%u)",
942  p->l4.vars.sctp.chunk_types[i]);
943  SCJbAppendString(js, unknown);
944  }
945  }
946  SCJbClose(js);
947  SCJbSetBool(js, "has_init", p->l4.vars.sctp.has_init);
948  SCJbSetBool(js, "has_init_ack", p->l4.vars.sctp.has_init_ack);
949  SCJbSetBool(js, "has_data", p->l4.vars.sctp.has_data);
950  SCJbSetBool(js, "has_abort", p->l4.vars.sctp.has_abort);
951  SCJbClose(js);
952  }
953  break;
954  }
955 
956  SCJbSetString(js, "pkt_src", PktSrcToString(p->pkt_src));
957 
958  if (eve_ctx != NULL) {
959  EveAddCommonOptions(&eve_ctx->cfg, p, f, js, dir);
960  }
961 
962  return js;
963 }
964 
966  const char *event_type, JsonAddrInfo *addr, uint64_t tx_id, OutputJsonCtx *eve_ctx)
967 {
968  SCJsonBuilder *js = CreateEveHeader(p, dir, event_type, addr, eve_ctx);
969  if (unlikely(js == NULL))
970  return NULL;
971 
972  /* tx id for correlation with other events */
973  SCJbSetUint(js, "tx_id", tx_id);
974 
975  return js;
976 }
977 
978 int OutputJSONMemBufferCallback(const char *str, size_t size, void *data)
979 {
980  OutputJSONMemBufferWrapper *wrapper = data;
981  MemBuffer **memb = wrapper->buffer;
982 
983  if (MEMBUFFER_OFFSET(*memb) + size >= MEMBUFFER_SIZE(*memb)) {
984  MemBufferExpand(memb, wrapper->expand_by);
985  }
986 
987  DEBUG_VALIDATE_BUG_ON(size > UINT32_MAX);
988  MemBufferWriteRaw((*memb), (const uint8_t *)str, (uint32_t)size);
989  return 0;
990 }
991 
992 int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer **buffer)
993 {
994  if (file_ctx->sensor_name) {
995  json_object_set_new(js, "host",
996  json_string(file_ctx->sensor_name));
997  }
998 
999  if (file_ctx->is_pcap_offline) {
1000  json_object_set_new(js, "pcap_filename", json_string(PcapFileGetFilename()));
1001  }
1002 
1003  if (file_ctx->prefix) {
1004  MemBufferWriteRaw((*buffer), (const uint8_t *)file_ctx->prefix, file_ctx->prefix_len);
1005  }
1006 
1007  OutputJSONMemBufferWrapper wrapper = {
1008  .buffer = buffer,
1009  .expand_by = JSON_OUTPUT_BUFFER_SIZE
1010  };
1011 
1012  int r = json_dump_callback(js, OutputJSONMemBufferCallback, &wrapper,
1013  file_ctx->json_flags);
1014  if (r != 0)
1015  return TM_ECODE_OK;
1016 
1017  LogFileWrite(file_ctx, *buffer);
1018  return 0;
1019 }
1020 
1022  ThreadVars *tv, const Packet *p, Flow *f, SCJsonBuilder *js, OutputJsonThreadCtx *ctx)
1023 {
1024  LogFileCtx *file_ctx = ctx->file_ctx;
1025  MemBuffer **buffer = &ctx->buffer;
1026  if (file_ctx->sensor_name) {
1027  SCJbSetString(js, "host", file_ctx->sensor_name);
1028  }
1029 
1030  if (file_ctx->is_pcap_offline) {
1031  SCJbSetString(js, "pcap_filename", PcapFileGetFilename());
1032  }
1033 
1034  SCEveRunCallbacks(tv, p, f, js);
1035 
1036  SCJbClose(js);
1037 
1038  MemBufferReset(*buffer);
1039 
1040  if (file_ctx->prefix) {
1041  MemBufferWriteRaw((*buffer), (const uint8_t *)file_ctx->prefix, file_ctx->prefix_len);
1042  }
1043 
1044  size_t jslen = SCJbLen(js);
1045  DEBUG_VALIDATE_BUG_ON(SCJbLen(js) > UINT32_MAX);
1046  size_t remaining = MEMBUFFER_SIZE(*buffer) - MEMBUFFER_OFFSET(*buffer);
1047  if (jslen >= remaining) {
1048  size_t expand_by = jslen + 1 - remaining;
1049  if (MemBufferExpand(buffer, (uint32_t)expand_by) < 0) {
1050  if (!ctx->too_large_warning) {
1051  /* Log a warning once, and include enough of the log
1052  * message to hopefully identify the event_type. */
1053  char partial[120];
1054  size_t partial_len = MIN(sizeof(partial), jslen);
1055  memcpy(partial, SCJbPtr(js), partial_len - 1);
1056  partial[partial_len - 1] = '\0';
1057  SCLogWarning("Formatted JSON EVE record too large, will be dropped: %s", partial);
1058  ctx->too_large_warning = true;
1059  }
1060  return;
1061  }
1062  }
1063 
1064  MemBufferWriteRaw((*buffer), SCJbPtr(js), (uint32_t)jslen);
1065  LogFileWrite(file_ctx, *buffer);
1066 }
1067 
1068 static inline enum LogFileType FileTypeFromConf(const char *typestr)
1069 {
1070  enum LogFileType log_filetype = LOGFILE_TYPE_NOTSET;
1071 
1072  if (typestr == NULL) {
1073  log_filetype = LOGFILE_TYPE_FILE;
1074  } else if (strcmp(typestr, "file") == 0 || strcmp(typestr, "regular") == 0) {
1075  log_filetype = LOGFILE_TYPE_FILE;
1076  } else if (strcmp(typestr, "unix_dgram") == 0) {
1077  log_filetype = LOGFILE_TYPE_UNIX_DGRAM;
1078  } else if (strcmp(typestr, "unix_stream") == 0) {
1079  log_filetype = LOGFILE_TYPE_UNIX_STREAM;
1080  } else if (strcmp(typestr, "redis") == 0) {
1081 #ifdef HAVE_LIBHIREDIS
1082  log_filetype = LOGFILE_TYPE_REDIS;
1083 #else
1084  FatalError("redis JSON output option is not compiled");
1085 #endif
1086  }
1087  SCLogDebug("type %s, file type value %d", typestr, log_filetype);
1088  return log_filetype;
1089 }
1090 
1091 static int LogFileTypePrepare(
1092  OutputJsonCtx *json_ctx, enum LogFileType log_filetype, SCConfNode *conf)
1093 {
1094 
1095  if (log_filetype == LOGFILE_TYPE_FILE || log_filetype == LOGFILE_TYPE_UNIX_DGRAM ||
1096  log_filetype == LOGFILE_TYPE_UNIX_STREAM) {
1097  if (SCConfLogOpenGeneric(conf, json_ctx->file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
1098  return -1;
1099  }
1100  }
1101 #ifdef HAVE_LIBHIREDIS
1102  else if (log_filetype == LOGFILE_TYPE_REDIS) {
1103  SCLogRedisInit();
1104  SCConfNode *redis_node = SCConfNodeLookupChild(conf, "redis");
1105  if (!json_ctx->file_ctx->sensor_name) {
1106  char hostname[1024];
1107  gethostname(hostname, 1023);
1108  json_ctx->file_ctx->sensor_name = SCStrdup(hostname);
1109  }
1110  if (json_ctx->file_ctx->sensor_name == NULL) {
1111  return -1;
1112  }
1113 
1114  if (SCConfLogOpenRedis(redis_node, json_ctx->file_ctx) < 0) {
1115  return -1;
1116  }
1117  }
1118 #endif
1119  else if (log_filetype == LOGFILE_TYPE_FILETYPE) {
1120  if (json_ctx->file_ctx->threaded) {
1121  /* Prepare for threaded log output. */
1122  if (!SCLogOpenThreadedFile(NULL, NULL, json_ctx->file_ctx)) {
1123  return -1;
1124  }
1125  }
1126  if (json_ctx->filetype->Init(conf, json_ctx->file_ctx->threaded,
1127  &json_ctx->file_ctx->filetype.init_data) < 0) {
1128  return -1;
1129  }
1130  if (json_ctx->filetype->ThreadInit) {
1131  if (json_ctx->filetype->ThreadInit(json_ctx->file_ctx->filetype.init_data, 0,
1132  &json_ctx->file_ctx->filetype.thread_data) < 0) {
1133  return -1;
1134  }
1135  }
1136  json_ctx->file_ctx->filetype.filetype = json_ctx->filetype;
1137  }
1138 
1139  return 0;
1140 }
1141 
1142 /**
1143  * \brief Create a new LogFileCtx for "fast" output style.
1144  * \param conf The configuration node for this output.
1145  * \return A LogFileCtx pointer on success, NULL on failure.
1146  */
1148 {
1149  OutputInitResult result = { NULL, false };
1150  OutputCtx *output_ctx = NULL;
1151 
1152  OutputJsonCtx *json_ctx = SCCalloc(1, sizeof(OutputJsonCtx));
1153  if (unlikely(json_ctx == NULL)) {
1154  SCLogDebug("could not create new OutputJsonCtx");
1155  return result;
1156  }
1157 
1158  /* First lookup a sensor-name value in this outputs configuration
1159  * node (deprecated). If that fails, lookup the global one. */
1160  const char *sensor_name = SCConfNodeLookupChildValue(conf, "sensor-name");
1161  if (sensor_name != NULL) {
1162  SCLogWarning("Found deprecated eve-log setting \"sensor-name\". "
1163  "Please set sensor-name globally.");
1164  }
1165  else {
1166  (void)SCConfGet("sensor-name", &sensor_name);
1167  }
1168 
1169  json_ctx->file_ctx = LogFileNewCtx();
1170  if (unlikely(json_ctx->file_ctx == NULL)) {
1171  SCLogDebug("AlertJsonInitCtx: Could not create new LogFileCtx");
1172  goto error_exit;
1173  }
1174 
1175  if (sensor_name) {
1176  json_ctx->file_ctx->sensor_name = SCStrdup(sensor_name);
1177  if (json_ctx->file_ctx->sensor_name == NULL) {
1178  goto error_exit;
1179  }
1180  } else {
1181  json_ctx->file_ctx->sensor_name = NULL;
1182  }
1183 
1184  output_ctx = SCCalloc(1, sizeof(OutputCtx));
1185  if (unlikely(output_ctx == NULL)) {
1186  goto error_exit;
1187  }
1188 
1189  output_ctx->data = json_ctx;
1190  output_ctx->DeInit = OutputJsonDeInitCtx;
1191 
1192  if (conf) {
1193  const char *output_s = SCConfNodeLookupChildValue(conf, "filetype");
1194  // Backwards compatibility
1195  if (output_s == NULL) {
1196  output_s = SCConfNodeLookupChildValue(conf, "type");
1197  }
1198 
1199  enum LogFileType log_filetype = FileTypeFromConf(output_s);
1200  if (log_filetype == LOGFILE_TYPE_NOTSET) {
1201  SCEveFileType *filetype = SCEveFindFileType(output_s);
1202  if (filetype != NULL) {
1203  log_filetype = LOGFILE_TYPE_FILETYPE;
1204  json_ctx->filetype = filetype;
1205  } else
1206  FatalError("Invalid JSON output option: %s", output_s);
1207  }
1208 
1209  const SCConfNode *compress_ipv6 = SCConfNodeLookupChild(conf, "ipv6-compress");
1210  if (compress_ipv6 && compress_ipv6->val && SCConfValIsTrue(compress_ipv6->val)) {
1211  SCLogConfig("Will compress IPv6 addresses in EVE output per RFC 5952");
1212  json_ctx->cfg.compress_ipv6 = true;
1213  } else {
1214  json_ctx->cfg.compress_ipv6 = false;
1215  }
1216 
1217  const char *prefix = SCConfNodeLookupChildValue(conf, "prefix");
1218  if (prefix != NULL)
1219  {
1220  SCLogInfo("Using prefix '%s' for JSON messages", prefix);
1221  json_ctx->file_ctx->prefix = SCStrdup(prefix);
1222  if (json_ctx->file_ctx->prefix == NULL)
1223  {
1224  FatalError("Failed to allocate memory for eve-log.prefix setting.");
1225  }
1226  json_ctx->file_ctx->prefix_len = (uint32_t)strlen(prefix);
1227  }
1228 
1229  /* Threaded file output */
1230  const SCConfNode *threaded = SCConfNodeLookupChild(conf, "threaded");
1231  if (threaded && threaded->val && SCConfValIsTrue(threaded->val)) {
1232  SCLogConfig("Threaded EVE logging configured");
1233  json_ctx->file_ctx->threaded = true;
1234  } else {
1235  json_ctx->file_ctx->threaded = false;
1236  }
1237  if (LogFileTypePrepare(json_ctx, log_filetype, conf) < 0) {
1238  goto error_exit;
1239  }
1240 
1241  const char *sensor_id_s = SCConfNodeLookupChildValue(conf, "sensor-id");
1242  if (sensor_id_s != NULL) {
1243  if (StringParseUint64((uint64_t *)&sensor_id, 10, 0, sensor_id_s) < 0) {
1244  FatalError("Failed to initialize JSON output, "
1245  "invalid sensor-id: %s",
1246  sensor_id_s);
1247  }
1248  }
1249 
1250  /* Check if top-level metadata should be logged. */
1251  const SCConfNode *metadata = SCConfNodeLookupChild(conf, "metadata");
1252  if (metadata && metadata->val && SCConfValIsFalse(metadata->val)) {
1253  SCLogConfig("Disabling eve metadata logging.");
1254  json_ctx->cfg.include_metadata = false;
1255  } else {
1256  json_ctx->cfg.include_metadata = true;
1257  }
1258 
1259  /* Check if ethernet information should be logged. */
1260  const SCConfNode *ethernet = SCConfNodeLookupChild(conf, "ethernet");
1261  if (ethernet && ethernet->val && SCConfValIsTrue(ethernet->val)) {
1262  SCLogConfig("Enabling Ethernet MAC address logging.");
1263  json_ctx->cfg.include_ethernet = true;
1264  } else {
1265  json_ctx->cfg.include_ethernet = false;
1266  }
1267 
1268  const SCConfNode *suriver = SCConfNodeLookupChild(conf, "suricata-version");
1269  if (suriver && suriver->val && SCConfValIsTrue(suriver->val)) {
1270  SCLogConfig("Enabling Suricata version logging.");
1271  json_ctx->cfg.include_suricata_version = true;
1272  } else {
1273  json_ctx->cfg.include_suricata_version = false;
1274  }
1275 
1276  /* See if we want to enable the community id */
1277  const SCConfNode *community_id = SCConfNodeLookupChild(conf, "community-id");
1278  if (community_id && community_id->val && SCConfValIsTrue(community_id->val)) {
1279  SCLogConfig("Enabling eve community_id logging.");
1280  json_ctx->cfg.include_community_id = true;
1281  } else {
1282  json_ctx->cfg.include_community_id = false;
1283  }
1284  const char *cid_seed = SCConfNodeLookupChildValue(conf, "community-id-seed");
1285  if (cid_seed != NULL) {
1286  if (StringParseUint16(&json_ctx->cfg.community_id_seed,
1287  10, 0, cid_seed) < 0)
1288  {
1289  FatalError("Failed to initialize JSON output, "
1290  "invalid community-id-seed: %s",
1291  cid_seed);
1292  }
1293  }
1294 
1295  /* Do we have a global eve xff configuration? */
1296  const SCConfNode *xff = SCConfNodeLookupChild(conf, "xff");
1297  if (xff != NULL) {
1298  json_ctx->xff_cfg = SCCalloc(1, sizeof(HttpXFFCfg));
1299  if (likely(json_ctx->xff_cfg != NULL)) {
1300  HttpXFFGetCfg(conf, json_ctx->xff_cfg);
1301  }
1302  }
1303 
1304  const char *pcapfile_s = SCConfNodeLookupChildValue(conf, "pcap-file");
1305  if (pcapfile_s != NULL && SCConfValIsTrue(pcapfile_s)) {
1306  json_ctx->file_ctx->is_pcap_offline =
1308  }
1309  json_ctx->file_ctx->type = log_filetype;
1310  }
1311 
1312  SCLogDebug("returning output_ctx %p", output_ctx);
1313 
1314  result.ctx = output_ctx;
1315  result.ok = true;
1316  return result;
1317 
1318 error_exit:
1319  if (json_ctx->file_ctx) {
1320  if (json_ctx->file_ctx->prefix) {
1321  SCFree(json_ctx->file_ctx->prefix);
1322  }
1323  LogFileFreeCtx(json_ctx->file_ctx);
1324  }
1325  SCFree(json_ctx);
1326 
1327  if (output_ctx) {
1328  SCFree(output_ctx);
1329  }
1330  return result;
1331 }
1332 
1333 static void OutputJsonDeInitCtx(OutputCtx *output_ctx)
1334 {
1335  OutputJsonCtx *json_ctx = (OutputJsonCtx *)output_ctx->data;
1336  LogFileCtx *logfile_ctx = json_ctx->file_ctx;
1337  if (logfile_ctx->dropped) {
1338  SCLogWarning("%" PRIu64 " events were dropped due to slow or "
1339  "disconnected socket",
1340  logfile_ctx->dropped);
1341  }
1342  if (json_ctx->xff_cfg != NULL) {
1343  SCFree(json_ctx->xff_cfg);
1344  }
1345  LogFileFreeCtx(logfile_ctx);
1346  SCFree(json_ctx);
1347  SCFree(output_ctx);
1348 }
PKT_IS_TOCLIENT
#define PKT_IS_TOCLIENT(p)
Definition: decode.h:240
FlowVar_::fv_float
FlowVarTypeFloat fv_float
Definition: flow-var.h:66
util-device-private.h
util-byte.h
MacSetSide
MacSetSide
Definition: util-macset.h:28
Packet_::proto
uint8_t proto
Definition: decode.h:537
pad0
uint8_t pad0
Definition: decode-template.h:1
SCOutputJsonLogDirection
SCOutputJsonLogDirection
Definition: output-eve-bindgen.h:33
SCConfValIsTrue
int SCConfValIsTrue(const char *val)
Check if a value is true.
Definition: conf.c:578
detect-engine.h
LOGFILE_TYPE_REDIS
@ LOGFILE_TYPE_REDIS
Definition: util-logopenfile.h:42
LogFileCtx_::sensor_name
char * sensor_name
Definition: util-logopenfile.h:121
OutputJsonCtx_::xff_cfg
HttpXFFCfg * xff_cfg
Definition: output-json.h:81
Flow_::flags
uint64_t flags
Definition: flow.h:403
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
CreateIsoTimeString
void CreateIsoTimeString(const SCTime_t ts, char *str, size_t size)
Definition: util-time.c:210
OutputJsonCtx_::cfg
OutputJsonCommonSettings cfg
Definition: output-json.h:80
HttpXFFGetCfg
void HttpXFFGetCfg(SCConfNode *conf, HttpXFFCfg *result)
Function to return XFF configuration from a configuration node.
Definition: app-layer-htp-xff.c:219
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
FILE_SHA256
#define FILE_SHA256
Definition: util-file.h:119
SCFlowGetStorageById
void * SCFlowGetStorageById(const Flow *f, SCFlowStorageId id)
Definition: flow-storage.c:40
LogFileNewCtx
LogFileCtx * LogFileNewCtx(void)
LogFileNewCtx() Get a new LogFileCtx.
Definition: util-logopenfile.c:735
PcapPacketCntGet
uint64_t PcapPacketCntGet(const Packet *p)
Definition: decode.c:1180
MemBufferExpand
int MemBufferExpand(MemBuffer **buffer, uint32_t expand_by)
expand membuffer by size of 'expand_by'
Definition: util-buffer.c:60
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
SCTPVars_::chunk_types
uint8_t chunk_types[SCTP_MAX_TRACKED_CHUNKS]
Definition: decode-sctp.h:82
name
const char * name
Definition: detect-engine-proto.c:48
Flow_::proto
uint8_t proto
Definition: flow.h:376
FlowVarTypeStr::value_len
uint16_t value_len
Definition: flow-var.h:41
FLOWVAR_TYPE_STR
#define FLOWVAR_TYPE_STR
Definition: flow-var.h:33
type
uint8_t type
Definition: decode-sctp.h:0
CreateEveHeader
SCJsonBuilder * CreateEveHeader(const Packet *p, enum SCOutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, OutputJsonCtx *eve_ctx)
Definition: output-json.c:819
JSON_OUTPUT_BUFFER_SIZE
#define JSON_OUTPUT_BUFFER_SIZE
Definition: output-json.h:54
TH_RST
#define TH_RST
Definition: decode-tcp.h:36
util-macset.h
OutputJsonCtx_
Definition: output-json.h:77
LogFileCtx_::json_flags
size_t json_flags
Definition: util-logopenfile.h:162
PrintInetIPv6
const char * PrintInetIPv6(const void *src, char *dst, socklen_t size, bool compress_ipv6)
Definition: util-print.c:209
Packet_::vlan_idx
uint8_t vlan_idx
Definition: decode.h:543
Flow_
Flow data structure.
Definition: flow.h:354
File_::state
FileState state
Definition: util-file.h:149
OutputJsonCommonSettings_
Definition: output-json.h:62
JsonAddrInfoInit
void JsonAddrInfoInit(const Packet *p, enum SCOutputJsonLogDirection dir, JsonAddrInfo *addr, OutputJsonCommonSettings *cfg)
Definition: output-json.c:467
TH_FIN
#define TH_FIN
Definition: decode-tcp.h:34
util-syslog.h
ctx
struct Thresholds ctx
LiveDevice_
Definition: util-device-private.h:32
LogFileCtx_
Definition: util-logopenfile.h:77
StringParseUint16
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:296
SCConfGet
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
Definition: conf.c:353
PktVar_::next
struct PktVar_ * next
Definition: decode.h:315
FILE_STORE
#define FILE_STORE
Definition: util-file.h:122
File_::file_store_id
uint32_t file_store_id
Definition: util-file.h:152
FlowVar_::fv_str
FlowVarTypeStr fv_str
Definition: flow-var.h:64
LiveDeviceGetById
LiveDevice * LiveDeviceGetById(const int id)
Definition: util-device.c:460
FlowVar_::keylen
FlowVarKeyLenType keylen
Definition: flow-var.h:58
LOGFILE_TYPE_NOTSET
@ LOGFILE_TYPE_NOTSET
Definition: util-logopenfile.h:45
SCTPVars_::chunk_cnt
uint8_t chunk_cnt
Definition: decode-sctp.h:80
SCProtoNameValid
bool SCProtoNameValid(uint16_t proto)
Function to check if the received protocol number is valid and do we have corresponding name entry fo...
Definition: util-proto-name.c:450
EveTcpFlags
void EveTcpFlags(const uint8_t flags, SCJsonBuilder *js)
jsonify tcp flags field Only add 'true' fields in an attempt to keep things reasonably compact.
Definition: output-json.c:447
output-eve-null.h
json_addr_info_zero
const JsonAddrInfo json_addr_info_zero
Definition: output-json.c:81
flow-bit.h
util-var-name.h
MIN
#define MIN(x, y)
Definition: suricata-common.h:416
util-log-redis.h
LOG_DIR_FLOW_TOSERVER
@ LOG_DIR_FLOW_TOSERVER
Definition: output-eve-bindgen.h:37
COMMUNITY_ID_BUF_SIZE
#define COMMUNITY_ID_BUF_SIZE
Definition: output-json.c:570
OutputJsonCommonSettings_::include_community_id
bool include_community_id
Definition: output-json.h:64
SCConfValIsFalse
int SCConfValIsFalse(const char *val)
Check if a value is false.
Definition: conf.c:603
OutputJSONMemBufferWrapper_::buffer
MemBuffer ** buffer
Definition: output-json.h:58
known_proto
const char * known_proto[256]
Definition: util-proto-name.c:40
OutputJsonBuilderBuffer
void OutputJsonBuilderBuffer(ThreadVars *tv, const Packet *p, Flow *f, SCJsonBuilder *js, OutputJsonThreadCtx *ctx)
Definition: output-json.c:1021
SCTPVars_::has_init
bool has_init
Definition: decode-sctp.h:84
FILE_STATE_TRUNCATED
@ FILE_STATE_TRUNCATED
Definition: util-file.h:140
proto
uint8_t proto
Definition: decode-template.h:0
p
Packet * p
Definition: fuzz_iprep.c:21
CreateEveFlowId
void CreateEveFlowId(SCJsonBuilder *js, const Flow *f)
Definition: output-json.c:685
SCConfNodeLookupChildValue
const char * SCConfNodeLookupChildValue(const SCConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
Definition: conf.c:878
Flow_::dp
Port dp
Definition: flow.h:370
JSONMACAddrInfo::dst
SCJsonBuilder * dst
Definition: output-json.c:711
FLOWVAR_TYPE_INT
#define FLOWVAR_TYPE_INT
Definition: flow-var.h:34
JSONMACAddrInfo
struct JSONMACAddrInfo JSONMACAddrInfo
File_::sha1
uint8_t sha1[SC_SHA1_LEN]
Definition: util-file.h:163
FLOW_IPV4
#define FLOW_IPV4
Definition: flow.h:99
GET_IPV6_DST_ADDR
#define GET_IPV6_DST_ADDR(p)
Definition: decode.h:205
util-unittest.h
SCJsonString
json_t * SCJsonString(const char *val)
Definition: output-json.c:96
OutputJsonCommonSettings_::include_suricata_version
bool include_suricata_version
Definition: output-json.h:67
util-unittest-helper.h
OutputCtx_::data
void * data
Definition: tm-modules.h:91
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:81
PrintStringsToBuffer
void PrintStringsToBuffer(uint8_t *dst_buf, uint32_t *dst_buf_offset_ptr, uint32_t dst_buf_size, const uint8_t *src_buf, const uint32_t src_buf_len)
Definition: util-print.c:195
OutputJsonRegister
void OutputJsonRegister(void)
Definition: output-json.c:83
OutputCtx_
Definition: tm-modules.h:88
RUNMODE_UNIX_SOCKET
@ RUNMODE_UNIX_SOCKET
Definition: runmodes.h:42
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
OutputJsonThreadCtx_
Definition: output-json.h:85
Packet_::icmp_s
struct Packet_::@32::@39 icmp_s
Packet_::datalink
int datalink
Definition: decode.h:651
File_::name_len
uint16_t name_len
Definition: util-file.h:148
FlowVar_::fv_int
FlowVarTypeInt fv_int
Definition: flow-var.h:65
LogFileCtx_::filetype
LogFileTypeCtx filetype
Definition: util-logopenfile.h:97
Flow_::dst
FlowAddress dst
Definition: flow.h:357
JsonAddrInfo_::dp
Port dp
Definition: output-json.h:45
File_::md5
uint8_t md5[SC_MD5_LEN]
Definition: util-file.h:161
SCRunmodeGet
SCRunMode SCRunmodeGet(void)
Get the current run mode.
Definition: suricata.c:301
LogFileWrite
int LogFileWrite(LogFileCtx *file_ctx, MemBuffer *buffer)
Definition: util-logopenfile.c:1115
util-debug.h
JB_SET_STRING
#define JB_SET_STRING(jb, key, val)
Definition: rust.h:36
Packet_::pktvar
PktVar * pktvar
Definition: decode.h:611
GenericVar_::next
struct GenericVar_ * next
Definition: util-var.h:57
GET_IPV4_DST_ADDR_PTR
#define GET_IPV4_DST_ADDR_PTR(p)
Definition: decode.h:200
PKT_IS_TOSERVER
#define PKT_IS_TOSERVER(p)
Definition: decode.h:239
DEFAULT_LOG_FILENAME
#define DEFAULT_LOG_FILENAME
Definition: output-json.c:66
EveAddCommonOptions
void EveAddCommonOptions(const OutputJsonCommonSettings *cfg, const Packet *p, const Flow *f, SCJsonBuilder *js, enum SCOutputJsonLogDirection dir)
Definition: output-json.c:395
File_::end
uint64_t end
Definition: util-file.h:173
DETECT_FLOWINT
@ DETECT_FLOWINT
Definition: detect-engine-register.h:69
OutputInitResult_::ctx
OutputCtx * ctx
Definition: output.h:47
LogFileCtx_::prefix_len
uint32_t prefix_len
Definition: util-logopenfile.h:138
DETECT_FLOWVAR
@ DETECT_FLOWVAR
Definition: detect-engine-register.h:67
Packet_::ts
SCTime_t ts
Definition: decode.h:569
output-json.h
FlowVar_::idx
uint32_t idx
Definition: flow-var.h:59
SCEveFileType_::ThreadInit
SCEveFileTypeThreadInitFunc ThreadInit
Initialize thread specific data.
Definition: output-eve-bindgen.h:161
JSONMACAddrInfo
Definition: output-json.c:710
PktVar_::value
uint8_t * value
Definition: decode.h:321
BOOL2STR
#define BOOL2STR(b)
Definition: util-debug.h:542
OutputRegisterModule
void OutputRegisterModule(const char *, const char *, OutputInitFunc)
OutputJsonInitCtx
OutputInitResult OutputJsonInitCtx(SCConfNode *conf)
Create a new LogFileCtx for "fast" output style.
Definition: output-json.c:1147
util-print.h
FlowVar_::key
uint8_t * key
Definition: flow-var.h:68
GET_PKT_DATA
#define GET_PKT_DATA(p)
Definition: decode.h:210
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
SCTP_GET_RAW_VTAG
#define SCTP_GET_RAW_VTAG(sctph)
Definition: decode-sctp.h:94
PrintInet
const char * PrintInet(int af, const void *src, char *dst, socklen_t size)
Definition: util-print.c:238
FlowVarTypeFloat_::value
double value
Definition: flow-var.h:51
Packet_::sp
Port sp
Definition: decode.h:522
FileTrackedSize
uint64_t FileTrackedSize(const File *file)
get the size of the file
Definition: util-file.c:325
SCEveFileType_::Init
SCEveFileTypeInitFunc Init
Function to initialize this filetype.
Definition: output-eve-bindgen.h:140
PktSrcToString
const char * PktSrcToString(enum PktSrcEnum pkt_src)
Definition: decode.c:881
TH_ACK
#define TH_ACK
Definition: decode-tcp.h:38
util-time.h
JB_SET_TRUE
#define JB_SET_TRUE(jb, key)
Definition: rust.h:37
OutputInitResult_::ok
bool ok
Definition: output.h:48
LiveDevice_::dev
char * dev
Definition: util-device-private.h:33
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:262
PktVar_::key
uint8_t * key
Definition: decode.h:320
SyslogInitialize
void SyslogInitialize(void)
Definition: output-eve-syslog.c:99
LogFileCtx_::type
enum LogFileType type
Definition: util-logopenfile.h:109
LOG_DIR_FLOW
@ LOG_DIR_FLOW
Definition: output-eve-bindgen.h:35
LOGFILE_TYPE_FILE
@ LOGFILE_TYPE_FILE
Definition: util-logopenfile.h:39
IGMPVars_::rgmp
bool rgmp
Definition: decode-igmp.h:35
MAC_SET_DST
@ MAC_SET_DST
Definition: util-macset.h:28
JsonAddrInfo_::log_port
bool log_port
Definition: output-json.h:48
JsonAddrInfo_
Definition: output-json.h:41
source-pcap-file-helper.h
NullLogInitialize
void NullLogInitialize(void)
Definition: output-eve-null.c:66
Packet_
Definition: decode.h:515
EveFileInfo
void EveFileInfo(SCJsonBuilder *jb, const File *ff, const uint64_t tx_id, const uint16_t flags)
Definition: output-json.c:124
OutputJSONMemBufferWrapper_
Definition: output-json.h:57
GET_PKT_LEN
#define GET_PKT_LEN(p)
Definition: decode.h:209
MacSet_
Definition: util-macset.c:45
conf.h
Packet_::l4
struct PacketL4 l4
Definition: decode.h:615
JSONFormatAndAddMACAddr
void JSONFormatAndAddMACAddr(SCJsonBuilder *js, const char *key, const uint8_t *val, bool is_array)
Definition: output-json.c:697
Port
uint16_t Port
Definition: decode.h:219
File_::name
uint8_t * name
Definition: util-file.h:155
TH_ECN
#define TH_ECN
Definition: decode-tcp.h:41
HttpXFFCfg_
Definition: app-layer-htp-xff.h:41
LOGFILE_TYPE_UNIX_DGRAM
@ LOGFILE_TYPE_UNIX_DGRAM
Definition: util-logopenfile.h:40
LogFileTypeCtx_::thread_data
void * thread_data
Definition: util-logopenfile.h:68
SCLogOpenThreadedFile
bool SCLogOpenThreadedFile(const char *log_path, const char *append, LogFileCtx *parent_ctx)
Definition: util-logopenfile.c:394
util-proto-name.h
SCTPVars_::has_abort
bool has_abort
Definition: decode-sctp.h:87
OutputJsonCommonSettings_::include_ethernet
bool include_ethernet
Definition: output-json.h:65
__attribute__
typedef __attribute__
DNP3 application header.
File_::sid
uint32_t * sid
Definition: util-file.h:175
LOGFILE_TYPE_UNIX_STREAM
@ LOGFILE_TYPE_UNIX_STREAM
Definition: util-logopenfile.h:41
EvePacket
void EvePacket(const Packet *p, SCJsonBuilder *js, uint32_t max_length)
Jsonify a packet.
Definition: output-json.c:422
MemBuffer_
Definition: util-buffer.h:27
File_::sid_cnt
uint32_t sid_cnt
Definition: util-file.h:176
TH_URG
#define TH_URG
Definition: decode-tcp.h:39
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:232
EveAddMetadata
void EveAddMetadata(const Packet *p, const Flow *f, SCJsonBuilder *js)
Definition: output-json.c:372
VAR_TYPE_FLOW_FLOAT
@ VAR_TYPE_FLOW_FLOAT
Definition: util-var.h:38
FlowVarTypeInt_::value
uint32_t value
Definition: flow-var.h:46
Flow_::src
FlowAddress src
Definition: flow.h:357
Flow_::flowvar
GenericVar * flowvar
Definition: flow.h:489
OutputJsonCommonSettings_::compress_ipv6
bool compress_ipv6
Definition: output-json.h:66
OutputJsonCommonSettings_::include_metadata
bool include_metadata
Definition: output-json.h:63
JsonAddrInfo_::proto
char proto[JSON_PROTO_LEN]
Definition: output-json.h:46
MAC_SET_SRC
@ MAC_SET_SRC
Definition: util-macset.h:28
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:850
PacketL4::L4Vars::sctp
SCTPVars sctp
Definition: decode.h:494
FILE_STATE_CLOSED
@ FILE_STATE_CLOSED
Definition: util-file.h:138
File_
Definition: util-file.h:146
TH_PUSH
#define TH_PUSH
Definition: decode-tcp.h:37
flow-storage.h
cnt
uint32_t cnt
Definition: tmqh-packetpool.h:7
OutputInitResult_
Definition: output.h:46
FlowVarTypeStr::value
uint8_t * value
Definition: flow-var.h:40
Packet_::flow
struct Flow_ * flow
Definition: decode.h:563
SCTPVars_::tracked_chunk_cnt
uint8_t tracked_chunk_cnt
Definition: decode-sctp.h:81
StringParseUint64
int StringParseUint64(uint64_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:264
VAR_TYPE_FLOW_BIT
@ VAR_TYPE_FLOW_BIT
Definition: util-var.h:36
GET_IPV4_SRC_ADDR_PTR
#define GET_IPV4_SRC_ADDR_PTR(p)
Definition: decode.h:199
PrintBufferData
#define PrintBufferData(buf, buf_offset_ptr, buf_size,...)
Definition: util-print.h:27
TH_SYN
#define TH_SYN
Definition: decode-tcp.h:35
flags
uint8_t flags
Definition: decode-gre.h:0
OutputJSONMemBufferWrapper_::expand_by
uint32_t expand_by
Definition: output-json.h:59
SCNtohs
#define SCNtohs(x)
Definition: suricata-common.h:439
suricata-common.h
JsonAddrInfo_::sp
Port sp
Definition: output-json.h:44
FLOW_IPV6
#define FLOW_IPV6
Definition: flow.h:101
OutputCtx_::DeInit
void(* DeInit)(struct OutputCtx_ *)
Definition: tm-modules.h:94
Flow_::icmp_d
struct Flow_::@123::@129 icmp_d
LogFileTypeCtx_::init_data
void * init_data
Definition: util-logopenfile.h:67
VarNameStoreLookupById
const char * VarNameStoreLookupById(const uint32_t id, const enum VarTypes type)
find name for id+type at packet time. As the active store won't be modified, we don't need locks.
Definition: util-var-name.c:307
MacSetSize
int MacSetSize(const MacSet *ms)
Definition: util-macset.c:246
GenericVar_
Definition: util-var.h:53
JSON_ADDR_LEN
#define JSON_ADDR_LEN
Definition: output-json.h:37
FILE_STORED
#define FILE_STORED
Definition: util-file.h:123
Packet_::livedev_id
uint16_t livedev_id
Definition: decode.h:632
FLOWVAR_TYPE_FLOAT
#define FLOWVAR_TYPE_FLOAT
Definition: flow-var.h:35
FILE_MD5
#define FILE_MD5
Definition: util-file.h:115
LogFileFreeCtx
int LogFileFreeCtx(LogFileCtx *lf_ctx)
LogFileFreeCtx() Destroy a LogFileCtx (Close the file and free memory)
Definition: util-logopenfile.c:952
output-eve-syslog.h
util-classification-config.h
CreateEveHeaderWithTxId
SCJsonBuilder * CreateEveHeaderWithTxId(const Packet *p, enum SCOutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, uint64_t tx_id, OutputJsonCtx *eve_ctx)
Definition: output-json.c:965
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
FatalError
#define FatalError(...)
Definition: util-debug.h:517
Flow_::parent_id
int64_t parent_id
Definition: flow.h:430
FlowBit_::idx
uint32_t idx
Definition: flow-bit.h:33
DETECT_FLOWBITS
@ DETECT_FLOWBITS
Definition: detect-engine-register.h:66
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:33
File_::sha256
uint8_t sha256[SC_SHA256_LEN]
Definition: util-file.h:165
File_::start
uint64_t start
Definition: util-file.h:172
JB_SET_FALSE
#define JB_SET_FALSE(jb, key)
Definition: rust.h:38
util-optimize.h
util-validate.h
FlowVar_::data
union FlowVar_::@116 data
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
JsonAddrInfo_::src_ip
char src_ip[JSON_ADDR_LEN]
Definition: output-json.h:42
FlowBit_
Definition: flow-bit.h:30
str
#define str(s)
Definition: suricata-common.h:316
SCConfLogOpenGeneric
int SCConfLogOpenGeneric(SCConfNode *conf, LogFileCtx *log_ctx, const char *default_filename, int rotate)
open a generic output "log file", which may be a regular file or a socket
Definition: util-logopenfile.c:499
GET_IPV6_SRC_ADDR
#define GET_IPV6_SRC_ADDR(p)
Definition: decode.h:204
SCFree
#define SCFree(p)
Definition: util-mem.h:61
Packet_::pkt_src
uint8_t pkt_src
Definition: decode.h:625
util-logopenfile.h
MacSetGetFirst
uint8_t * MacSetGetFirst(const MacSet *ms, MacSetSide side)
Definition: util-macset.c:233
MEMBUFFER_SIZE
#define MEMBUFFER_SIZE(mem_buffer)
Get the MemBuffers current size.
Definition: util-buffer.h:61
src
uint16_t src
Definition: app-layer-dnp3.h:5
util-buffer.h
TH_CWR
#define TH_CWR
Definition: decode-tcp.h:43
VAR_TYPE_FLOW_VAR
@ VAR_TYPE_FLOW_VAR
Definition: util-var.h:39
MacSetForEach
int MacSetForEach(const MacSet *ms, MacSetIteratorFunc IterFunc, void *data)
Definition: util-macset.c:220
SCTPVars_::has_data
bool has_data
Definition: decode-sctp.h:86
LogFileCtx_::prefix
char * prefix
Definition: util-logopenfile.h:137
JsonAddrInfo_::dst_ip
char dst_ip[JSON_ADDR_LEN]
Definition: output-json.h:43
VAR_TYPE_FLOW_INT
@ VAR_TYPE_FLOW_INT
Definition: util-var.h:37
LogFileCtx_::is_pcap_offline
bool is_pcap_offline
Definition: util-logopenfile.h:165
PcapFileGetFilename
const char * PcapFileGetFilename(void)
Definition: source-pcap-file-helper.c:168
GenericVar_::type
uint16_t type
Definition: util-var.h:54
PktVar_::value_len
uint16_t value_len
Definition: decode.h:319
MAX_JSON_SIZE
#define MAX_JSON_SIZE
Definition: output-json.c:69
OutputJsonCtx_::file_ctx
LogFileCtx * file_ctx
Definition: output-json.h:78
OutputJSONMemBufferCallback
int OutputJSONMemBufferCallback(const char *str, size_t size, void *data)
Definition: output-json.c:978
JSONMACAddrInfo::src
SCJsonBuilder * src
Definition: output-json.c:711
OutputJSONBuffer
int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer **buffer)
Definition: output-json.c:992
FILE_SHA1
#define FILE_SHA1
Definition: util-file.h:117
PacketL4::L4Vars::igmp
IGMPVars igmp
Definition: decode.h:493
LogFileType
LogFileType
Definition: util-logopenfile.h:38
MemBufferWriteRaw
uint32_t MemBufferWriteRaw(MemBuffer *dst, const uint8_t *raw, const uint32_t raw_len)
Write a raw buffer to the MemBuffer dst.
Definition: util-buffer.c:115
SCEveFindFileType
SCEveFileType * SCEveFindFileType(const char *name)
Definition: output-eve.c:81
LOG_DIR_PACKET
@ LOG_DIR_PACKET
Definition: output-eve-bindgen.h:34
LOG_DIR_FLOW_TOCLIENT
@ LOG_DIR_FLOW_TOCLIENT
Definition: output-eve-bindgen.h:36
IGMPVars_::version
uint8_t version
Definition: decode-igmp.h:34
PktVar_
Definition: decode.h:313
Packet_::vlan_id
uint16_t vlan_id[VLAN_MAX_LAYERS]
Definition: decode.h:542
likely
#define likely(expr)
Definition: util-optimize.h:32
IPPROTO_SCTP
#define IPPROTO_SCTP
Definition: decode.h:1272
Flow_::icmp_s
struct Flow_::@121::@127 icmp_s
Flow_::sp
Port sp
Definition: flow.h:359
dst
uint16_t dst
Definition: app-layer-dnp3.h:4
PROG_VER
#define PROG_VER
Definition: suricata.h:76
LogFileTypeCtx_::filetype
SCEveFileType * filetype
Definition: util-logopenfile.h:66
OutputJsonCommonSettings_::community_id_seed
uint16_t community_id_seed
Definition: output-json.h:68
flow.h
MEMBUFFER_OFFSET
#define MEMBUFFER_OFFSET(mem_buffer)
Get the MemBuffers current offset.
Definition: util-buffer.h:56
Packet_::dp
Port dp
Definition: decode.h:530
PktVar_::key_len
uint16_t key_len
Definition: decode.h:318
RUNMODE_PCAP_FILE
@ RUNMODE_PCAP_FILE
Definition: runmodes.h:30
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SCConfNode_
Definition: conf.h:37
flow-var.h
SCConfNode_::val
char * val
Definition: conf.h:39
FILE_STATE_ERROR
@ FILE_STATE_ERROR
Definition: util-file.h:142
FlowVar_
Definition: flow-var.h:55
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:109
SCTPVars_::has_init_ack
bool has_init_ack
Definition: decode-sctp.h:85
Flow_::tenant_id
uint32_t tenant_id
Definition: flow.h:424
VAR_TYPE_PKT_VAR
@ VAR_TYPE_PKT_VAR
Definition: util-var.h:33
PacketL4::vars
union PacketL4::L4Vars vars
LOGFILE_TYPE_FILETYPE
@ LOGFILE_TYPE_FILETYPE
Definition: util-logopenfile.h:44
FlowVar_::datatype
uint8_t datatype
Definition: flow-var.h:57
FILE_HAS_GAPS
#define FILE_HAS_GAPS
Definition: util-file.h:126
output.h
PktVar_::id
uint32_t id
Definition: decode.h:314
SCEveRunCallbacks
void SCEveRunCallbacks(ThreadVars *tv, const Packet *p, Flow *f, SCJsonBuilder *jb)
Definition: output-eve.c:52
LogFileCtx_::threaded
bool threaded
Definition: util-logopenfile.h:104
MODULE_NAME
#define MODULE_NAME
Definition: output-json.c:67
SCEveFileType_
Structure used to define an EVE output file type.
Definition: output-eve-bindgen.h:110
MacSetGetFlowStorageID
SCFlowStorageId MacSetGetFlowStorageID(void)
Definition: util-macset.c:113
OutputJsonCtx_::filetype
SCEveFileType * filetype
Definition: output-json.h:82