suricata
decode.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2024 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  * \defgroup decode Packet decoding
20  *
21  * \brief Code in charge of protocol decoding
22  *
23  * The task of decoding packets is made in different files and
24  * as Suricata is supporting encapsulation there is a potential
25  * recursivity in the call.
26  *
27  * For each protocol a DecodePROTO function is provided. For
28  * example we have DecodeIPV4() for IPv4 and DecodePPP() for
29  * PPP.
30  *
31  * These functions have all a pkt and a len argument which
32  * are respectively a pointer to the protocol data and the length
33  * of this protocol data.
34  *
35  * \attention The pkt parameter must point to the effective data because
36  * it will be used later to set per protocol pointer like Packet::tcph
37  *
38  * @{
39  */
40 
41 
42 /**
43  * \file
44  *
45  * \author Victor Julien <victor@inliniac.net>
46  *
47  * Decode the raw packet
48  */
49 
50 #include "suricata-common.h"
51 #include "decode.h"
52 
53 #include "packet.h"
54 #include "flow.h"
55 #include "flow-storage.h"
56 #include "tmqh-packetpool.h"
57 #include "app-layer.h"
58 #include "output.h"
59 
60 #include "decode-vxlan.h"
61 #include "decode-geneve.h"
62 #include "decode-erspan.h"
63 #include "decode-teredo.h"
64 
65 #include "defrag-hash.h"
66 
67 #include "util-hash.h"
68 #include "util-hash-string.h"
69 #include "util-print.h"
70 #include "util-profiling.h"
71 #include "util-validate.h"
72 #include "util-debug.h"
73 #include "util-exception-policy.h"
74 #include "action-globals.h"
75 
76 uint32_t default_packet_size = 0;
77 extern bool stats_decoder_events;
78 extern const char *stats_decoder_events_prefix;
79 extern bool stats_stream_events;
82 
83 /* Settings order as in the enum */
84 // clang-format off
87  /* EXCEPTION_POLICY_NOT_SET */ false,
88  /* EXCEPTION_POLICY_AUTO */ false,
89  /* EXCEPTION_POLICY_PASS_PACKET */ true,
90  /* EXCEPTION_POLICY_PASS_FLOW */ false,
91  /* EXCEPTION_POLICY_BYPASS_FLOW */ true,
92  /* EXCEPTION_POLICY_DROP_PACKET */ false,
93  /* EXCEPTION_POLICY_DROP_FLOW */ false,
94  /* EXCEPTION_POLICY_REJECT */ true,
95  },
96  .valid_settings_ips = {
97  /* EXCEPTION_POLICY_NOT_SET */ false,
98  /* EXCEPTION_POLICY_AUTO */ false,
99  /* EXCEPTION_POLICY_PASS_PACKET */ true,
100  /* EXCEPTION_POLICY_PASS_FLOW */ false,
101  /* EXCEPTION_POLICY_BYPASS_FLOW */ true,
102  /* EXCEPTION_POLICY_DROP_PACKET */ true,
103  /* EXCEPTION_POLICY_DROP_FLOW */ false,
104  /* EXCEPTION_POLICY_REJECT */ true,
105  },
106 };
107 // clang-format on
108 
109 /* Settings order as in the enum */
110 // clang-format off
112  .valid_settings_ids = {
113  /* EXCEPTION_POLICY_NOT_SET */ false,
114  /* EXCEPTION_POLICY_AUTO */ false,
115  /* EXCEPTION_POLICY_PASS_PACKET */ true,
116  /* EXCEPTION_POLICY_PASS_FLOW */ false,
117  /* EXCEPTION_POLICY_BYPASS_FLOW */ true,
118  /* EXCEPTION_POLICY_DROP_PACKET */ false,
119  /* EXCEPTION_POLICY_DROP_FLOW */ false,
120  /* EXCEPTION_POLICY_REJECT */ true,
121  },
122  .valid_settings_ips = {
123  /* EXCEPTION_POLICY_NOT_SET */ false,
124  /* EXCEPTION_POLICY_AUTO */ false,
125  /* EXCEPTION_POLICY_PASS_PACKET */ true,
126  /* EXCEPTION_POLICY_PASS_FLOW */ false,
127  /* EXCEPTION_POLICY_BYPASS_FLOW */ true,
128  /* EXCEPTION_POLICY_DROP_PACKET */ true,
129  /* EXCEPTION_POLICY_DROP_FLOW */ false,
130  /* EXCEPTION_POLICY_REJECT */ true,
131  },
132 };
133 // clang-format on
134 
135 /**
136  * \brief Initialize PacketAlerts with dynamic alerts array size
137  *
138  */
140 {
141  PacketAlert *pa_array = SCCalloc(packet_alert_max, sizeof(PacketAlert));
142  BUG_ON(pa_array == NULL);
143 
144  return pa_array;
145 }
146 
148 {
149  if (pa != NULL) {
150  SCFree(pa);
151  }
152 }
153 
154 static int DecodeTunnel(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t,
156 
157 static int DecodeTunnel(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt,
158  uint32_t len, enum DecodeTunnelProto proto)
159 {
160  switch (proto) {
161  case DECODE_TUNNEL_PPP:
162  return DecodePPP(tv, dtv, p, pkt, len);
163  case DECODE_TUNNEL_IPV4:
164  DEBUG_VALIDATE_BUG_ON(len > UINT16_MAX);
165  return DecodeIPV4(tv, dtv, p, pkt, (uint16_t)len);
166  case DECODE_TUNNEL_IPV6:
168  DEBUG_VALIDATE_BUG_ON(len > UINT16_MAX);
169  return DecodeIPV6(tv, dtv, p, pkt, (uint16_t)len);
170  case DECODE_TUNNEL_VLAN:
171  return DecodeVLAN(tv, dtv, p, pkt, len);
173  return DecodeEthernet(tv, dtv, p, pkt, len);
175  return DecodeERSPAN(tv, dtv, p, pkt, len);
177  return DecodeERSPANTypeI(tv, dtv, p, pkt, len);
178  case DECODE_TUNNEL_NSH:
179  return DecodeNSH(tv, dtv, p, pkt, len);
180  default:
181  SCLogDebug("FIXME: DecodeTunnel: protocol %" PRIu32 " not supported.", proto);
182  break;
183  }
184  return TM_ECODE_OK;
185 }
186 
187 /**
188  * \brief Return a malloced packet.
189  */
191 {
192  PacketDestructor(p);
193  SCFree(p);
194 }
195 
196 /**
197  * \brief Finalize decoding of a packet
198  *
199  * This function needs to be call at the end of decode
200  * functions when decoding has been successful.
201  *
202  */
204 {
205  if (p->flags & PKT_IS_INVALID) {
207  }
208 }
209 
212 {
213  for (uint8_t i = 0; i < p->events.cnt; i++) {
214  const uint8_t e = p->events.events[i];
215 
217  continue;
219  continue;
221  }
222 }
223 
224 /**
225  * \brief Get a malloced packet.
226  *
227  * \retval p packet, NULL on error
228  */
230 {
231  Packet *p = SCCalloc(1, SIZE_OF_PACKET);
232  if (unlikely(p == NULL)) {
233  return NULL;
234  }
235  PacketInit(p);
237 
238  SCLogDebug("allocated a new packet only using alloc...");
239 
241  return p;
242 }
243 
244 /**
245  * \brief Return a packet to where it was allocated.
246  */
248 {
249  if (likely(p->pool != NULL)) {
252  } else {
253  PacketFree(p);
254  }
255 }
256 
257 /**
258  * \brief Get a packet. We try to get a packet from the packetpool first, but
259  * if that is empty we alloc a packet that is free'd again after
260  * processing.
261  *
262  * \retval p packet, NULL on error
263  */
265 {
266  /* try the pool first */
268 
269  if (p == NULL) {
270  /* non fatal, we're just not processing a packet then */
271  p = PacketGetFromAlloc();
272  } else {
275  }
276 
277  return p;
278 }
279 
280 inline int PacketCallocExtPkt(Packet *p, int datalen)
281 {
282  if (! p->ext_pkt) {
283  p->ext_pkt = SCCalloc(1, datalen);
284  if (unlikely(p->ext_pkt == NULL)) {
285  SET_PKT_LEN(p, 0);
286  return -1;
287  }
288  }
289  return 0;
290 }
291 
292 /**
293  * \brief Copy data to Packet payload at given offset
294  *
295  * This function copies data/payload to a Packet. It uses the
296  * space allocated at Packet creation (pointed by Packet::pkt)
297  * or allocate some memory (pointed by Packet::ext_pkt) if the
298  * data size is to big to fit in initial space (of size
299  * default_packet_size).
300  *
301  * \param Pointer to the Packet to modify
302  * \param Offset of the copy relatively to payload of Packet
303  * \param Pointer to the data to copy
304  * \param Length of the data to copy
305  */
306 inline int PacketCopyDataOffset(Packet *p, uint32_t offset, const uint8_t *data, uint32_t datalen)
307 {
308  if (unlikely(offset + datalen > MAX_PAYLOAD_SIZE)) {
309  /* too big */
310  SET_PKT_LEN(p, 0);
311  return -1;
312  }
313 
314  /* Do we have already an packet with allocated data */
315  if (! p->ext_pkt) {
316  uint32_t newsize = offset + datalen;
317  // check overflow
318  if (newsize < offset)
319  return -1;
320  if (newsize <= default_packet_size) {
321  /* data will fit in memory allocated with packet */
322  memcpy(GET_PKT_DIRECT_DATA(p) + offset, data, datalen);
323  } else {
324  /* here we need a dynamic allocation */
326  if (unlikely(p->ext_pkt == NULL)) {
327  SET_PKT_LEN(p, 0);
328  return -1;
329  }
330  /* copy initial data */
332  /* copy data as asked */
333  memcpy(p->ext_pkt + offset, data, datalen);
334  }
335  } else {
336  memcpy(p->ext_pkt + offset, data, datalen);
337  }
338  return 0;
339 }
340 
341 /**
342  * \brief Copy data to Packet payload and set packet length
343  *
344  * \param Pointer to the Packet to modify
345  * \param Pointer to the data to copy
346  * \param Length of the data to copy
347  */
348 inline int PacketCopyData(Packet *p, const uint8_t *pktdata, uint32_t pktlen)
349 {
350  SET_PKT_LEN(p, (size_t)pktlen);
351  return PacketCopyDataOffset(p, 0, pktdata, pktlen);
352 }
353 
354 /**
355  * \brief Setup a pseudo packet (tunnel)
356  *
357  * \param parent parent packet for this pseudo pkt
358  * \param pkt raw packet data
359  * \param len packet data length
360  * \param proto protocol of the tunneled packet
361  *
362  * \retval p the pseudo packet or NULL if out of memory
363  */
365  const uint8_t *pkt, uint32_t len, enum DecodeTunnelProto proto)
366 {
367  int ret;
368 
369  SCEnter();
370 
371  if (parent->nb_decoded_layers + 1 >= decoder_max_layers) {
373  SCReturnPtr(NULL, "Packet");
374  }
375 
376  /* get us a packet */
378  if (unlikely(p == NULL)) {
379  SCReturnPtr(NULL, "Packet");
380  }
381 
382  /* copy packet and set length, proto */
383  PacketCopyData(p, pkt, len);
384  DEBUG_VALIDATE_BUG_ON(parent->recursion_level == 255);
385  p->recursion_level = parent->recursion_level + 1;
387  p->nb_decoded_layers = parent->nb_decoded_layers + 1;
388  p->ts = parent->ts;
389  p->datalink = DLT_RAW;
390  p->tenant_id = parent->tenant_id;
391  p->livedev = parent->livedev;
392 
393  /* set the root ptr to the lowest layer */
394  if (parent->root != NULL) {
395  p->root = parent->root;
396  BUG_ON(parent->ttype != PacketTunnelChild);
397  } else {
398  p->root = parent;
399  parent->ttype = PacketTunnelRoot;
400  }
401  /* tell new packet it's part of a tunnel */
403 
404  ret = DecodeTunnel(tv, dtv, p, GET_PKT_DATA(p),
405  GET_PKT_LEN(p), proto);
406 
407  if (unlikely(ret != TM_ECODE_OK) ||
409  {
410  /* Not a (valid) tunnel packet */
411  SCLogDebug("tunnel packet is invalid");
412  p->root = NULL;
414  SCReturnPtr(NULL, "Packet");
415  }
416 
417  /* Update tunnel settings in parent */
418  if (parent->root == NULL) {
419  parent->ttype = PacketTunnelRoot;
420  }
421  TUNNEL_INCR_PKT_TPR(p);
422 
423  /* disable payload (not packet) inspection on the parent, as the payload
424  * is the packet we will now run through the system separately. We do
425  * check it against the ip/port/other header checks though */
426  DecodeSetNoPayloadInspectionFlag(parent);
427  SCReturnPtr(p, "Packet");
428 }
429 
430 /**
431  * \brief Setup a pseudo packet (reassembled frags)
432  *
433  * Difference with PacketPseudoPktSetup is that this func doesn't increment
434  * the recursion level. It needs to be on the same level as the frags because
435  * we run the flow engine against this and we need to get the same flow.
436  *
437  * \param parent parent packet for this pseudo pkt
438  * \param pkt raw packet data
439  * \param len packet data length
440  * \param proto protocol of the tunneled packet
441  *
442  * \retval p the pseudo packet or NULL if out of memory
443  */
444 Packet *PacketDefragPktSetup(Packet *parent, const uint8_t *pkt, uint32_t len, uint8_t proto)
445 {
446  SCEnter();
447 
448  /* get us a packet */
450  if (unlikely(p == NULL)) {
451  SCReturnPtr(NULL, "Packet");
452  }
453 
454  /* set the root ptr to the lowest layer */
455  if (parent->root != NULL) {
456  p->root = parent->root;
457  BUG_ON(parent->ttype != PacketTunnelChild);
458  } else {
459  p->root = parent;
460  // we set parent->ttype later
461  }
462  /* tell new packet it's part of a tunnel */
464 
465  /* copy packet and set length, proto */
466  if (pkt && len) {
467  PacketCopyData(p, pkt, len);
468  }
469  p->recursion_level = parent->recursion_level; /* NOT incremented */
470  p->ts = parent->ts;
471  p->tenant_id = parent->tenant_id;
472  memcpy(&p->vlan_id[0], &parent->vlan_id[0], sizeof(p->vlan_id));
473  p->vlan_idx = parent->vlan_idx;
474  p->livedev = parent->livedev;
475 
476  SCReturnPtr(p, "Packet");
477 }
478 
479 /**
480  * \brief inform defrag "parent" that a pseudo packet is
481  * now associated to it.
482  */
484 {
485  /* tell parent packet it's part of a tunnel */
486  if (parent->ttype == PacketTunnelNone)
487  parent->ttype = PacketTunnelRoot;
488 
489  /* increment tunnel packet refcnt in the root packet */
490  TUNNEL_INCR_PKT_TPR(parent);
491 
492  /* disable payload (not packet) inspection on the parent, as the payload
493  * is the packet we will now run through the system separately. We do
494  * check it against the ip/port/other header checks though */
495  DecodeSetNoPayloadInspectionFlag(parent);
496 }
497 
498 /**
499  * \note if p->flow is set, the flow is locked
500  */
502 {
503  if (PKT_IS_PSEUDOPKT(p))
504  return;
505 
506 #ifdef CAPTURE_OFFLOAD
507  /* Don't try to bypass if flow is already out or
508  * if we have failed to do it once */
509  if (p->flow) {
510  int state = p->flow->flow_state;
511  if ((state == FLOW_STATE_LOCAL_BYPASSED) ||
512  (state == FLOW_STATE_CAPTURE_BYPASSED)) {
513  return;
514  }
515 
516  FlowBypassInfo *fc;
517 
519  if (fc == NULL) {
520  fc = SCCalloc(sizeof(FlowBypassInfo), 1);
521  if (fc) {
523  } else {
524  return;
525  }
526  }
527  }
528  if (p->BypassPacketsFlow && p->BypassPacketsFlow(p)) {
529  if (p->flow) {
530  FlowUpdateState(p->flow, FLOW_STATE_CAPTURE_BYPASSED);
531  }
532  } else {
533  if (p->flow) {
535  }
536  }
537 #else /* CAPTURE_OFFLOAD */
538  if (p->flow) {
539  int state = p->flow->flow_state;
540  if (state == FLOW_STATE_LOCAL_BYPASSED)
541  return;
543  }
544 #endif
545 }
546 
547 /** \brief switch direction of a packet */
549 {
550  if (PKT_IS_TOSERVER(p)) {
553 
557  }
558  } else {
561 
565  }
566  }
567 }
568 
569 /* counter name store */
570 static HashTable *g_counter_table = NULL;
571 static SCMutex g_counter_table_mutex = SCMUTEX_INITIALIZER;
572 
574 {
575  SCMutexLock(&g_counter_table_mutex);
576  if (g_counter_table) {
577  HashTableFree(g_counter_table);
578  g_counter_table = NULL;
579  }
580  SCMutexUnlock(&g_counter_table_mutex);
581 }
582 
583 static bool IsDefragMemcapExceptionPolicyStatsValid(enum ExceptionPolicy policy)
584 {
585  if (EngineModeIsIPS()) {
587  }
589 }
590 
591 static bool IsFlowMemcapExceptionPolicyStatsValid(enum ExceptionPolicy policy)
592 {
593  if (EngineModeIsIPS()) {
595  }
597 }
598 
600 {
601  /* register counters */
602  dtv->counter_pkts = StatsRegisterCounter("decoder.pkts", tv);
603  dtv->counter_bytes = StatsRegisterCounter("decoder.bytes", tv);
604  dtv->counter_invalid = StatsRegisterCounter("decoder.invalid", tv);
605  dtv->counter_ipv4 = StatsRegisterCounter("decoder.ipv4", tv);
606  dtv->counter_ipv6 = StatsRegisterCounter("decoder.ipv6", tv);
607  dtv->counter_eth = StatsRegisterCounter("decoder.ethernet", tv);
608  dtv->counter_arp = StatsRegisterCounter("decoder.arp", tv);
609  dtv->counter_ethertype_unknown = StatsRegisterCounter("decoder.unknown_ethertype", tv);
610  dtv->counter_chdlc = StatsRegisterCounter("decoder.chdlc", tv);
611  dtv->counter_raw = StatsRegisterCounter("decoder.raw", tv);
612  dtv->counter_null = StatsRegisterCounter("decoder.null", tv);
613  dtv->counter_sll = StatsRegisterCounter("decoder.sll", tv);
614  dtv->counter_tcp = StatsRegisterCounter("decoder.tcp", tv);
615 
617  dtv->counter_tcp_synack = StatsRegisterCounter("tcp.synack", tv);
619 
620  dtv->counter_udp = StatsRegisterCounter("decoder.udp", tv);
621  dtv->counter_sctp = StatsRegisterCounter("decoder.sctp", tv);
622  dtv->counter_esp = StatsRegisterCounter("decoder.esp", tv);
623  dtv->counter_icmpv4 = StatsRegisterCounter("decoder.icmpv4", tv);
624  dtv->counter_icmpv6 = StatsRegisterCounter("decoder.icmpv6", tv);
625  dtv->counter_ppp = StatsRegisterCounter("decoder.ppp", tv);
626  dtv->counter_pppoe = StatsRegisterCounter("decoder.pppoe", tv);
627  dtv->counter_geneve = StatsRegisterCounter("decoder.geneve", tv);
628  dtv->counter_gre = StatsRegisterCounter("decoder.gre", tv);
629  dtv->counter_vlan = StatsRegisterCounter("decoder.vlan", tv);
630  dtv->counter_vlan_qinq = StatsRegisterCounter("decoder.vlan_qinq", tv);
631  dtv->counter_vlan_qinqinq = StatsRegisterCounter("decoder.vlan_qinqinq", tv);
632  dtv->counter_vxlan = StatsRegisterCounter("decoder.vxlan", tv);
633  dtv->counter_vntag = StatsRegisterCounter("decoder.vntag", tv);
634  dtv->counter_ieee8021ah = StatsRegisterCounter("decoder.ieee8021ah", tv);
635  dtv->counter_teredo = StatsRegisterCounter("decoder.teredo", tv);
636  dtv->counter_ipv4inipv6 = StatsRegisterCounter("decoder.ipv4_in_ipv6", tv);
637  dtv->counter_ipv6inipv6 = StatsRegisterCounter("decoder.ipv6_in_ipv6", tv);
638  dtv->counter_mpls = StatsRegisterCounter("decoder.mpls", tv);
639  dtv->counter_avg_pkt_size = StatsRegisterAvgCounter("decoder.avg_pkt_size", tv);
640  dtv->counter_max_pkt_size = StatsRegisterMaxCounter("decoder.max_pkt_size", tv);
641  dtv->counter_max_mac_addrs_src = StatsRegisterMaxCounter("decoder.max_mac_addrs_src", tv);
642  dtv->counter_max_mac_addrs_dst = StatsRegisterMaxCounter("decoder.max_mac_addrs_dst", tv);
643  dtv->counter_erspan = StatsRegisterMaxCounter("decoder.erspan", tv);
644  dtv->counter_nsh = StatsRegisterMaxCounter("decoder.nsh", tv);
645  dtv->counter_flow_memcap = StatsRegisterCounter("flow.memcap", tv);
647  FlowGetMemcapExceptionPolicy(), "flow.memcap_exception_policy.",
648  IsFlowMemcapExceptionPolicyStatsValid);
649 
650  dtv->counter_tcp_active_sessions = StatsRegisterCounter("tcp.active_sessions", tv);
651  dtv->counter_flow_total = StatsRegisterCounter("flow.total", tv);
652  dtv->counter_flow_active = StatsRegisterCounter("flow.active", tv);
655  dtv->counter_flow_icmp4 = StatsRegisterCounter("flow.icmpv4", tv);
656  dtv->counter_flow_icmp6 = StatsRegisterCounter("flow.icmpv6", tv);
657  dtv->counter_flow_tcp_reuse = StatsRegisterCounter("flow.tcp_reuse", tv);
658  dtv->counter_flow_get_used = StatsRegisterCounter("flow.get_used", tv);
659  dtv->counter_flow_get_used_eval = StatsRegisterCounter("flow.get_used_eval", tv);
660  dtv->counter_flow_get_used_eval_reject = StatsRegisterCounter("flow.get_used_eval_reject", tv);
661  dtv->counter_flow_get_used_eval_busy = StatsRegisterCounter("flow.get_used_eval_busy", tv);
662  dtv->counter_flow_get_used_failed = StatsRegisterCounter("flow.get_used_failed", tv);
663 
664  dtv->counter_flow_spare_sync_avg = StatsRegisterAvgCounter("flow.wrk.spare_sync_avg", tv);
665  dtv->counter_flow_spare_sync = StatsRegisterCounter("flow.wrk.spare_sync", tv);
666  dtv->counter_flow_spare_sync_incomplete = StatsRegisterCounter("flow.wrk.spare_sync_incomplete", tv);
667  dtv->counter_flow_spare_sync_empty = StatsRegisterCounter("flow.wrk.spare_sync_empty", tv);
668 
670  StatsRegisterCounter("defrag.ipv4.fragments", tv);
671  dtv->counter_defrag_ipv4_reassembled = StatsRegisterCounter("defrag.ipv4.reassembled", tv);
673  StatsRegisterCounter("defrag.ipv6.fragments", tv);
674  dtv->counter_defrag_ipv6_reassembled = StatsRegisterCounter("defrag.ipv6.reassembled", tv);
676  StatsRegisterCounter("defrag.max_frag_hits", tv);
677 
679  DefragGetMemcapExceptionPolicy(), "defrag.memcap_exception_policy.",
680  IsDefragMemcapExceptionPolicyStatsValid);
681 
682  for (int i = 0; i < DECODE_EVENT_MAX; i++) {
683  BUG_ON(i != (int)DEvents[i].code);
684 
686  continue;
688  continue;
689 
690  if (i < DECODE_EVENT_PACKET_MAX &&
691  strncmp(DEvents[i].event_name, "decoder.", 8) == 0)
692  {
693  SCMutexLock(&g_counter_table_mutex);
694  if (g_counter_table == NULL) {
695  g_counter_table = HashTableInit(256, StringHashFunc,
698  if (g_counter_table == NULL) {
699  FatalError("decoder counter hash "
700  "table init failed");
701  }
702  }
703 
704  char name[256];
705  char *dot = strchr(DEvents[i].event_name, '.');
706  BUG_ON(!dot);
707  snprintf(name, sizeof(name), "%s.%s",
709 
710  const char *found = HashTableLookup(g_counter_table, name, 0);
711  if (!found) {
712  char *add = SCStrdup(name);
713  if (add == NULL)
714  FatalError("decoder counter hash "
715  "table name init failed");
716  int r = HashTableAdd(g_counter_table, add, 0);
717  if (r != 0)
718  FatalError("decoder counter hash "
719  "table name add failed");
720  found = add;
721  }
723  found, tv);
724 
725  SCMutexUnlock(&g_counter_table_mutex);
726  } else {
728  DEvents[i].event_name, tv);
729  }
730  }
731 
732  return;
733 }
734 
736  const DecodeThreadVars *dtv, const Packet *p)
737 {
739  //StatsIncr(tv, dtv->counter_pkts_per_sec);
743 }
744 
745 /**
746  * \brief Debug print function for printing addresses
747  *
748  * \param Address object
749  *
750  * \todo IPv6
751  */
753 {
754  if (a == NULL)
755  return;
756 
757  switch (a->family) {
758  case AF_INET:
759  {
760  char s[16];
761  PrintInet(AF_INET, (const void *)&a->addr_data32[0], s, sizeof(s));
762  SCLogDebug("%s", s);
763  break;
764  }
765  }
766 }
767 
768 /** \brief Alloc and setup DecodeThreadVars */
770 {
771  DecodeThreadVars *dtv = NULL;
772 
773  if ((dtv = SCCalloc(1, sizeof(DecodeThreadVars))) == NULL)
774  return NULL;
775 
777 
779  SCLogError("initializing flow log API for thread failed");
781  return NULL;
782  }
783 
784  return dtv;
785 }
786 
788 {
789  if (dtv != NULL) {
790  if (dtv->app_tctx != NULL)
792 
793  if (dtv->output_flow_thread_data != NULL)
795 
796  SCFree(dtv);
797  }
798 }
799 
800 /**
801  * \brief Set data for Packet and set length when zero copy is used
802  *
803  * \param Pointer to the Packet to modify
804  * \param Pointer to the data
805  * \param Length of the data
806  */
807 inline int PacketSetData(Packet *p, const uint8_t *pktdata, uint32_t pktlen)
808 {
809  SET_PKT_LEN(p, (size_t)pktlen);
810  if (unlikely(!pktdata)) {
811  return -1;
812  }
813  // ext_pkt cannot be const (because we sometimes copy)
814  p->ext_pkt = (uint8_t *) pktdata;
815  p->flags |= PKT_ZERO_COPY;
816 
817  return 0;
818 }
819 
820 const char *PktSrcToString(enum PktSrcEnum pkt_src)
821 {
822  const char *pkt_src_str = NULL;
823  switch (pkt_src) {
824  case PKT_SRC_WIRE:
825  pkt_src_str = "wire/pcap";
826  break;
827  case PKT_SRC_DECODER_GRE:
828  pkt_src_str = "gre tunnel";
829  break;
831  pkt_src_str = "ipv4 tunnel";
832  break;
834  pkt_src_str = "ipv6 tunnel";
835  break;
837  pkt_src_str = "teredo tunnel";
838  break;
839  case PKT_SRC_DEFRAG:
840  pkt_src_str = "defrag";
841  break;
843  pkt_src_str = "stream (detect/log)";
844  break;
845  case PKT_SRC_FFR:
846  pkt_src_str = "stream (flow timeout)";
847  break;
849  pkt_src_str = "geneve encapsulation";
850  break;
852  pkt_src_str = "vxlan encapsulation";
853  break;
855  pkt_src_str = "detect reload flush";
856  break;
858  pkt_src_str = "capture timeout flush";
859  break;
861  pkt_src_str = "shutdown flush";
862  break;
863  }
864  DEBUG_VALIDATE_BUG_ON(pkt_src_str == NULL);
865  return pkt_src_str;
866 }
867 
869 {
870  switch (r) {
872  return "decode error";
874  return "defrag error";
876  return "defrag memcap";
878  return "flow memcap";
880  return "flow drop";
882  return "stream error";
884  return "stream memcap";
886  return "stream midstream";
888  return "stream reassembly";
890  return "applayer error";
892  return "applayer memcap";
894  return "rules";
896  return "threshold detection_filter";
898  return "nfq error";
900  return "tunnel packet drop";
902  case PKT_DROP_REASON_MAX:
903  return NULL;
904  }
905  return NULL;
906 }
907 
908 static const char *PacketDropReasonToJsonString(enum PacketDropReason r)
909 {
910  switch (r) {
912  return "ips.drop_reason.decode_error";
914  return "ips.drop_reason.defrag_error";
916  return "ips.drop_reason.defrag_memcap";
918  return "ips.drop_reason.flow_memcap";
920  return "ips.drop_reason.flow_drop";
922  return "ips.drop_reason.stream_error";
924  return "ips.drop_reason.stream_memcap";
926  return "ips.drop_reason.stream_midstream";
928  return "ips.drop_reason.stream_reassembly";
930  return "ips.drop_reason.applayer_error";
932  return "ips.drop_reason.applayer_memcap";
934  return "ips.drop_reason.rules";
936  return "ips.drop_reason.threshold_detection_filter";
938  return "ips.drop_reason.nfq_error";
940  return "ips.drop_reason.tunnel_packet_drop";
942  case PKT_DROP_REASON_MAX:
943  return NULL;
944  }
945  return NULL;
946 }
947 
948 typedef struct CaptureStats_ {
953 
956 
958 
960 {
961  if (!EngineModeIsIPS() || PKT_IS_PSEUDOPKT(p))
962  return;
963 
967  } else if (unlikely(PacketCheckAction(p, ACTION_DROP))) {
969  } else if (unlikely(p->flags & PKT_STREAM_MODIFIED)) {
971  } else {
973  }
976  }
977 }
978 
980 {
981  if (EngineModeIsIPS()) {
983  s->counter_ips_accepted = StatsRegisterCounter("ips.accepted", tv);
984  s->counter_ips_blocked = StatsRegisterCounter("ips.blocked", tv);
985  s->counter_ips_rejected = StatsRegisterCounter("ips.rejected", tv);
986  s->counter_ips_replaced = StatsRegisterCounter("ips.replaced", tv);
987  for (int i = PKT_DROP_REASON_NOT_SET; i < PKT_DROP_REASON_MAX; i++) {
988  const char *name = PacketDropReasonToJsonString(i);
989  if (name != NULL)
991  }
992  }
993 }
994 
996 {
1001  intmax_t value = 0;
1002  if (ConfGetInt("decoder.max-layers", &value) == 1) {
1003  if (value < 0 || value > UINT8_MAX) {
1004  SCLogWarning("Invalid value for decoder.max-layers");
1005  } else {
1006  decoder_max_layers = (uint8_t)value;
1007  }
1008  }
1010 }
1011 
1013 {
1014  intmax_t max = 0;
1015  if (ConfGetInt("packet-alert-max", &max) == 1) {
1016  if (max <= 0 || max > UINT8_MAX) {
1017  SCLogWarning("Invalid value for packet-alert-max, default value set instead");
1018  } else {
1019  packet_alert_max = (uint16_t)max;
1020  }
1021  }
1022  SCLogDebug("detect->packet_alert_max set to %d", packet_alert_max);
1023 }
1024 
1025 /**
1026  * @}
1027  */
PacketCheckAction
bool PacketCheckAction(const Packet *p, const uint8_t a)
Definition: packet.c:48
DecodeThreadVars_::counter_flow_get_used_eval_busy
uint16_t counter_flow_get_used_eval_busy
Definition: decode.h:1005
PKT_DROP_REASON_DEFRAG_MEMCAP
@ PKT_DROP_REASON_DEFRAG_MEMCAP
Definition: decode.h:378
PKT_DROP_REASON_DEFRAG_ERROR
@ PKT_DROP_REASON_DEFRAG_ERROR
Definition: decode.h:377
ConfGetInt
int ConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
Definition: conf.c:399
DecodeThreadVars_::counter_defrag_ipv4_reassembled
uint16_t counter_defrag_ipv4_reassembled
Definition: decode.h:985
util-hash-string.h
PKT_DROP_REASON_RULES_THRESHOLD
@ PKT_DROP_REASON_RULES_THRESHOLD
Definition: decode.h:384
DecodeThreadVars_::counter_ethertype_unknown
uint16_t counter_ethertype_unknown
Definition: decode.h:959
DecodeThreadVars_::counter_flow_udp
uint16_t counter_flow_udp
Definition: decode.h:998
len
uint8_t len
Definition: app-layer-dnp3.h:2
DecodeThreadVars_::counter_bytes
uint16_t counter_bytes
Definition: decode.h:939
DECODE_TUNNEL_IPV6
@ DECODE_TUNNEL_IPV6
Definition: decode.h:1068
CaptureStats_::counter_ips_blocked
uint16_t counter_ips_blocked
Definition: decode.c:950
decode-erspan.h
decode-vxlan.h
DecodeThreadVars_::counter_eth
uint16_t counter_eth
Definition: decode.h:947
DecodeThreadVars_::counter_flow_active
uint16_t counter_flow_active
Definition: decode.h:996
StatsIncr
void StatsIncr(ThreadVars *tv, uint16_t id)
Increments the local counter.
Definition: counters.c:167
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
DecodeERSPAN
int DecodeERSPAN(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
ERSPAN Type II.
Definition: decode-erspan.c:76
PacketFreeOrRelease
void PacketFreeOrRelease(Packet *p)
Return a packet to where it was allocated.
Definition: decode.c:247
DecodeThreadVars_::counter_flow_icmp4
uint16_t counter_flow_icmp4
Definition: decode.h:999
DecodeThreadVars_::counter_vxlan
uint16_t counter_vxlan
Definition: decode.h:972
DecodeThreadVars_::counter_max_pkt_size
uint16_t counter_max_pkt_size
Definition: decode.h:941
DecodePPP
int DecodePPP(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Definition: decode-ppp.c:174
PacketCopyData
int PacketCopyData(Packet *p, const uint8_t *pktdata, uint32_t pktlen)
Copy data to Packet payload and set packet length.
Definition: decode.c:348
PacketBypassCallback
void PacketBypassCallback(Packet *p)
Definition: decode.c:501
PKT_IS_PSEUDOPKT
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
Definition: decode.h:1315
DecodeThreadVars_::counter_avg_pkt_size
uint16_t counter_avg_pkt_size
Definition: decode.h:940
DecodeERSPANConfig
void DecodeERSPANConfig(void)
Functions to decode ERSPAN Type I and II packets.
Definition: decode-erspan.c:53
PacketPoolReturnPacket
void PacketPoolReturnPacket(Packet *p)
Return packet to Packet pool.
Definition: tmqh-packetpool.c:179
GetFlowBypassInfoID
FlowStorageId GetFlowBypassInfoID(void)
Definition: flow-util.c:211
FlowBypassInfo_
Definition: flow.h:530
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
PKT_DROP_REASON_STREAM_MEMCAP
@ PKT_DROP_REASON_STREAM_MEMCAP
Definition: decode.h:386
DecodeNSH
int DecodeNSH(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Function to decode NSH packets.
Definition: decode-nsh.c:46
PKT_DROP_REASON_FLOW_MEMCAP
@ PKT_DROP_REASON_FLOW_MEMCAP
Definition: decode.h:379
DecodeTeredoConfig
void DecodeTeredoConfig(void)
Definition: decode-teredo.c:104
CaptureStatsSetup
void CaptureStatsSetup(ThreadVars *tv)
Definition: decode.c:979
PacketDropReasonToString
const char * PacketDropReasonToString(enum PacketDropReason r)
Definition: decode.c:868
PacketEngineEvents_::events
uint8_t events[PACKET_ENGINE_EVENT_MAX]
Definition: decode.h:293
CaptureStats_
Definition: decode.c:948
PKT_STREAM_MODIFIED
#define PKT_STREAM_MODIFIED
Definition: decode.h:1267
DECODE_TUNNEL_IPV6_TEREDO
@ DECODE_TUNNEL_IPV6_TEREDO
Definition: decode.h:1069
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
PKT_SRC_SHUTDOWN_FLUSH
@ PKT_SRC_SHUTDOWN_FLUSH
Definition: decode.h:67
AddressDebugPrint
void AddressDebugPrint(Address *a)
Debug print function for printing addresses.
Definition: decode.c:752
PKT_SRC_DECODER_IPV4
@ PKT_SRC_DECODER_IPV4
Definition: decode.h:57
DecodeThreadVars_::counter_flow_spare_sync_avg
uint16_t counter_flow_spare_sync_avg
Definition: decode.h:1011
PacketDefragPktSetup
Packet * PacketDefragPktSetup(Packet *parent, const uint8_t *pkt, uint32_t len, uint8_t proto)
Setup a pseudo packet (reassembled frags)
Definition: decode.c:444
stats_stream_events
bool stats_stream_events
Definition: counters.c:104
PKT_ZERO_COPY
#define PKT_ZERO_COPY
Definition: decode.h:1280
PKT_SRC_CAPTURE_TIMEOUT
@ PKT_SRC_CAPTURE_TIMEOUT
Definition: decode.h:65
action-globals.h
Packet_::flags
uint32_t flags
Definition: decode.h:525
PacketAlertCreate
PacketAlert * PacketAlertCreate(void)
Initialize PacketAlerts with dynamic alerts array size.
Definition: decode.c:139
DecodeThreadVars_::counter_vntag
uint16_t counter_vntag
Definition: decode.h:973
Packet_::vlan_idx
uint8_t vlan_idx
Definition: decode.h:516
DecodeThreadVars_::counter_flow_get_used_eval
uint16_t counter_flow_get_used_eval
Definition: decode.h:1003
util-hash.h
ExceptionPolicyStatsSetts_
Definition: util-exception-policy-types.h:48
CaptureStats
struct CaptureStats_ CaptureStats
StatsSetUI64
void StatsSetUI64(ThreadVars *tv, uint16_t id, uint64_t x)
Sets a value of type double to the local counter.
Definition: counters.c:210
DECODE_EVENT_PACKET_MAX
@ DECODE_EVENT_PACKET_MAX
Definition: decode-events.h:224
Packet_::pool
struct PktPool_ * pool
Definition: decode.h:659
DecodeThreadVars_::counter_tcp_synack
uint16_t counter_tcp_synack
Definition: decode.h:953
PKT_DROP_REASON_MAX
@ PKT_DROP_REASON_MAX
Definition: decode.h:391
PKT_DROP_REASON_STREAM_REASSEMBLY
@ PKT_DROP_REASON_STREAM_REASSEMBLY
Definition: decode.h:388
DECODE_TUNNEL_ERSPANI
@ DECODE_TUNNEL_ERSPANI
Definition: decode.h:1065
DecodeThreadVars_::counter_teredo
uint16_t counter_teredo
Definition: decode.h:976
DecodeThreadVars_::counter_erspan
uint16_t counter_erspan
Definition: decode.h:980
PacketCopyDataOffset
int PacketCopyDataOffset(Packet *p, uint32_t offset, const uint8_t *data, uint32_t datalen)
Copy data to Packet payload at given offset.
Definition: decode.c:306
DecodeThreadVars_::counter_raw
uint16_t counter_raw
Definition: decode.h:962
SCMutexLock
#define SCMutexLock(mut)
Definition: threads-debug.h:117
FLOW_PKT_TOSERVER
#define FLOW_PKT_TOSERVER
Definition: flow.h:227
HashTable_
Definition: util-hash.h:35
ACTION_REJECT_ANY
#define ACTION_REJECT_ANY
Definition: action-globals.h:37
Address_
Definition: decode.h:116
flow_memcap_eps_stats
ExceptionPolicyStatsSetts flow_memcap_eps_stats
Definition: decode.c:111
DecodeThreadVars_::counter_arp
uint16_t counter_arp
Definition: decode.h:958
DecodeThreadVars_::counter_flow_tcp
uint16_t counter_flow_tcp
Definition: decode.h:997
SCMUTEX_INITIALIZER
#define SCMUTEX_INITIALIZER
Definition: threads-debug.h:121
PacketDecodeFinalize
void PacketDecodeFinalize(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
Finalize decoding of a packet.
Definition: decode.c:203
proto
uint8_t proto
Definition: decode-template.h:0
PacketAlertGetMaxConfig
void PacketAlertGetMaxConfig(void)
Definition: decode.c:1012
decoder_max_layers
uint8_t decoder_max_layers
Definition: decode.c:80
DecodeThreadVars_::counter_tcp_active_sessions
uint16_t counter_tcp_active_sessions
Definition: decode.h:994
Packet_::flowflags
uint8_t flowflags
Definition: decode.h:519
StringHashCompareFunc
char StringHashCompareFunc(void *data1, uint16_t datalen1, void *data2, uint16_t datalen2)
Definition: util-hash-string.c:38
Packet_::BypassPacketsFlow
int(* BypassPacketsFlow)(struct Packet_ *)
Definition: decode.h:583
TmqhOutputPacketpool
void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
Definition: tmqh-packetpool.c:317
DecodeVXLANConfig
void DecodeVXLANConfig(void)
Definition: decode-vxlan.c:98
PacketDropReason
PacketDropReason
Definition: decode.h:374
DecodeThreadVars_::counter_max_mac_addrs_src
uint16_t counter_max_mac_addrs_src
Definition: decode.h:942
DecodeUnregisterCounters
void DecodeUnregisterCounters(void)
Definition: decode.c:573
GET_PKT_DIRECT_MAX_SIZE
#define GET_PKT_DIRECT_MAX_SIZE(p)
Definition: decode.h:215
DecodeThreadVars_::counter_flow_get_used
uint16_t counter_flow_get_used
Definition: decode.h:1002
PacketTunnelChild
@ PacketTunnelChild
Definition: decode.h:397
tmqh-packetpool.h
StringHashFunc
uint32_t StringHashFunc(HashTable *ht, void *data, uint16_t datalen)
Definition: util-hash-string.c:33
Packet_::events
PacketEngineEvents events
Definition: decode.h:619
PacketAlertFree
void PacketAlertFree(PacketAlert *pa)
Definition: decode.c:147
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:84
HashTableFree
void HashTableFree(HashTable *ht)
Definition: util-hash.c:78
DecodeThreadVars_::counter_flow_spare_sync_empty
uint16_t counter_flow_spare_sync_empty
Definition: decode.h:1009
Flow_::flow_state
FlowStateType flow_state
Definition: flow.h:416
DecodeThreadVars_::counter_flow_tcp_reuse
uint16_t counter_flow_tcp_reuse
Definition: decode.h:1001
DECODE_TUNNEL_NSH
@ DECODE_TUNNEL_NSH
Definition: decode.h:1071
DecodeThreadVars_::counter_flow_total
uint16_t counter_flow_total
Definition: decode.h:995
Packet_::datalink
int datalink
Definition: decode.h:628
PKT_DEFAULT_MAX_DECODED_LAYERS
#define PKT_DEFAULT_MAX_DECODED_LAYERS
Definition: decode.h:1320
stats_decoder_events_prefix
const char * stats_decoder_events_prefix
Definition: counters.c:102
DLT_RAW
#define DLT_RAW
Definition: decode.h:1218
DecodeRegisterPerfCounters
void DecodeRegisterPerfCounters(DecodeThreadVars *dtv, ThreadVars *tv)
Definition: decode.c:599
DecodeThreadVars_::counter_flow_spare_sync
uint16_t counter_flow_spare_sync
Definition: decode.h:1008
DECODE_TUNNEL_ERSPANII
@ DECODE_TUNNEL_ERSPANII
Definition: decode.h:1064
SET_PKT_LEN
#define SET_PKT_LEN(p, len)
Definition: decode.h:217
DecodeThreadVars_::counter_ipv6inipv6
uint16_t counter_ipv6inipv6
Definition: decode.h:979
StatsRegisterMaxCounter
uint16_t StatsRegisterMaxCounter(const char *name, struct ThreadVars_ *tv)
Registers a counter, whose value holds the maximum of all the values assigned to it.
Definition: counters.c:1011
FLOW_STATE_LOCAL_BYPASSED
@ FLOW_STATE_LOCAL_BYPASSED
Definition: flow.h:508
decode.h
util-debug.h
DecodeThreadVars_::counter_flow_get_used_failed
uint16_t counter_flow_get_used_failed
Definition: decode.h:1006
PKT_SRC_WIRE
@ PKT_SRC_WIRE
Definition: decode.h:55
CaptureStats_::counter_ips_rejected
uint16_t counter_ips_rejected
Definition: decode.c:951
PKT_IS_TOSERVER
#define PKT_IS_TOSERVER(p)
Definition: decode.h:242
DecodeThreadVars_::counter_icmpv4
uint16_t counter_icmpv4
Definition: decode.h:956
DecodeThreadVars_::counter_ppp
uint16_t counter_ppp
Definition: decode.h:966
DecodeERSPANTypeI
int DecodeERSPANTypeI(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
ERSPAN Type I.
Definition: decode-erspan.c:65
DEvents
const struct DecodeEvents_ DEvents[]
Definition: decode-events.c:29
Packet_::ts
SCTime_t ts
Definition: decode.h:536
PKT_DROP_REASON_APPLAYER_ERROR
@ PKT_DROP_REASON_APPLAYER_ERROR
Definition: decode.h:381
OutputFlowLogThreadInit
TmEcode OutputFlowLogThreadInit(ThreadVars *tv, void *initdata, void **data)
thread init for the flow logger This will run the thread init functions for the individual registered...
Definition: output-flow.c:123
SCMutexUnlock
#define SCMutexUnlock(mut)
Definition: threads-debug.h:119
PacketSwap
void PacketSwap(Packet *p)
switch direction of a packet
Definition: decode.c:548
util-exception-policy.h
DecodeThreadVars_::counter_tcp_rst
uint16_t counter_tcp_rst
Definition: decode.h:954
PktSrcEnum
PktSrcEnum
Definition: decode.h:54
PKT_DROP_REASON_NOT_SET
@ PKT_DROP_REASON_NOT_SET
Definition: decode.h:375
DecodeTunnelProto
DecodeTunnelProto
Definition: decode.h:1062
PacketDestructor
void PacketDestructor(Packet *p)
Cleanup a packet so that we can free it. No memset needed..
Definition: packet.c:151
CaptureStatsUpdate
void CaptureStatsUpdate(ThreadVars *tv, const Packet *p)
Definition: decode.c:959
util-print.h
PKT_SRC_DECODER_TEREDO
@ PKT_SRC_DECODER_TEREDO
Definition: decode.h:59
AppLayerGetCtxThread
AppLayerThreadCtx * AppLayerGetCtxThread(ThreadVars *tv)
Creates a new app layer thread context.
Definition: app-layer.c:1059
SCEnter
#define SCEnter(...)
Definition: util-debug.h:271
GET_PKT_DATA
#define GET_PKT_DATA(p)
Definition: decode.h:213
ExceptionPolicySetStatsCounters
void ExceptionPolicySetStatsCounters(ThreadVars *tv, ExceptionPolicyCounters *counter, ExceptionPolicyStatsSetts *setting, enum ExceptionPolicy conf_policy, const char *default_str, bool(*isExceptionPolicyValid)(enum ExceptionPolicy))
Definition: util-exception-policy.c:298
HashTableLookup
void * HashTableLookup(HashTable *ht, void *data, uint16_t datalen)
Definition: util-hash.c:183
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
PrintInet
const char * PrintInet(int af, const void *src, char *dst, socklen_t size)
Definition: util-print.c:241
DECODE_TUNNEL_PPP
@ DECODE_TUNNEL_PPP
Definition: decode.h:1070
FLOW_PKT_TOCLIENT_FIRST
#define FLOW_PKT_TOCLIENT_FIRST
Definition: flow.h:233
FlowSetStorageById
int FlowSetStorageById(Flow *f, FlowStorageId id, void *ptr)
Definition: flow-storage.c:45
PacketFree
void PacketFree(Packet *p)
Return a malloced packet.
Definition: decode.c:190
PktSrcToString
const char * PktSrcToString(enum PktSrcEnum pkt_src)
Definition: decode.c:820
ExceptionPolicyStatsSetts_::valid_settings_ids
bool valid_settings_ids[EXCEPTION_POLICY_MAX]
Definition: util-exception-policy-types.h:50
DecodeThreadVars_::counter_vlan_qinq
uint16_t counter_vlan_qinq
Definition: decode.h:970
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:249
HashTableAdd
int HashTableAdd(HashTable *ht, void *data, uint16_t datalen)
Definition: util-hash.c:104
SIZE_OF_PACKET
#define SIZE_OF_PACKET
Definition: decode.h:692
StringHashFreeFunc
void StringHashFreeFunc(void *data)
Definition: util-hash-string.c:51
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:300
PKT_DROP_REASON_RULES
@ PKT_DROP_REASON_RULES
Definition: decode.h:383
util-profiling.h
PacketCallocExtPkt
int PacketCallocExtPkt(Packet *p, int datalen)
Definition: decode.c:280
PKT_SRC_STREAM_TCP_DETECTLOG_FLUSH
@ PKT_SRC_STREAM_TCP_DETECTLOG_FLUSH
Definition: decode.h:62
DECODE_TUNNEL_VLAN
@ DECODE_TUNNEL_VLAN
Definition: decode.h:1066
PKT_SRC_DECODER_IPV6
@ PKT_SRC_DECODER_IPV6
Definition: decode.h:58
CaptureStats_::counter_ips_accepted
uint16_t counter_ips_accepted
Definition: decode.c:949
Packet_
Definition: decode.h:488
DecodeThreadVars_::counter_nsh
uint16_t counter_nsh
Definition: decode.h:981
DecodeIPV6
int DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
Definition: decode-ipv6.c:561
DECODE_TUNNEL_IPV4
@ DECODE_TUNNEL_IPV4
Definition: decode.h:1067
GET_PKT_LEN
#define GET_PKT_LEN(p)
Definition: decode.h:212
DecodeThreadVars_::app_tctx
AppLayerThreadCtx * app_tctx
Definition: decode.h:935
decode-teredo.h
DecodeThreadVars_::counter_sll
uint16_t counter_sll
Definition: decode.h:961
PKT_DROP_REASON_STREAM_ERROR
@ PKT_DROP_REASON_STREAM_ERROR
Definition: decode.h:385
DecodeThreadVars_::counter_sctp
uint16_t counter_sctp
Definition: decode.h:964
Packet_::livedev
struct LiveDevice_ * livedev
Definition: decode.h:607
DecodeThreadVars_::counter_invalid
uint16_t counter_invalid
Definition: decode.h:945
DecodeThreadVars_::counter_ieee8021ah
uint16_t counter_ieee8021ah
Definition: decode.h:974
SCReturnPtr
#define SCReturnPtr(x, type)
Definition: util-debug.h:287
DecodeThreadVars_::counter_ipv4inipv6
uint16_t counter_ipv4inipv6
Definition: decode.h:978
FLOW_PKT_TOCLIENT
#define FLOW_PKT_TOCLIENT
Definition: flow.h:228
DecodeThreadVars_::counter_vlan
uint16_t counter_vlan
Definition: decode.h:969
DECODE_TUNNEL_ETHERNET
@ DECODE_TUNNEL_ETHERNET
Definition: decode.h:1063
DecodeThreadVars_::counter_tcp
uint16_t counter_tcp
Definition: decode.h:951
FlowGetStorageById
void * FlowGetStorageById(const Flow *f, FlowStorageId id)
Definition: flow-storage.c:40
DecodeThreadVars_::counter_pkts
uint16_t counter_pkts
Definition: decode.h:938
FlowUpdateState
void FlowUpdateState(Flow *f, const enum FlowState s)
Definition: flow.c:1158
PacketTunnelNone
@ PacketTunnelNone
Definition: decode.h:395
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:33
DecodeThreadVars_::counter_defrag_memcap_eps
ExceptionPolicyCounters counter_defrag_memcap_eps
Definition: decode.h:989
default_packet_size
uint32_t default_packet_size
Definition: decode.c:76
Packet_::nb_decoded_layers
uint8_t nb_decoded_layers
Definition: decode.h:633
PKT_SRC_DECODER_GENEVE
@ PKT_SRC_DECODER_GENEVE
Definition: decode.h:66
DecodeThreadVars_::counter_chdlc
uint16_t counter_chdlc
Definition: decode.h:948
Packet_::ReleasePacket
void(* ReleasePacket)(struct Packet_ *)
Definition: decode.h:580
flow-storage.h
Packet_::flow
struct Flow_ * flow
Definition: decode.h:527
Packet_::tenant_id
uint32_t tenant_id
Definition: decode.h:654
PKT_DROP_REASON_INNER_PACKET
@ PKT_DROP_REASON_INNER_PACKET
Definition: decode.h:390
FlowGetMemcapExceptionPolicy
enum ExceptionPolicy FlowGetMemcapExceptionPolicy(void)
Definition: flow.c:131
DecodeThreadVarsFree
void DecodeThreadVarsFree(ThreadVars *tv, DecodeThreadVars *dtv)
Definition: decode.c:787
DecodeThreadVars_::counter_flow_spare_sync_incomplete
uint16_t counter_flow_spare_sync_incomplete
Definition: decode.h:1010
PKT_DROP_REASON_APPLAYER_MEMCAP
@ PKT_DROP_REASON_APPLAYER_MEMCAP
Definition: decode.h:382
DecodeGlobalConfig
void DecodeGlobalConfig(void)
Definition: decode.c:995
suricata-common.h
PKT_SRC_FFR
@ PKT_SRC_FFR
Definition: decode.h:61
DecodeThreadVars_::counter_flow_icmp6
uint16_t counter_flow_icmp6
Definition: decode.h:1000
DecodeThreadVars_::counter_ipv6
uint16_t counter_ipv6
Definition: decode.h:950
packet.h
CaptureStats_::counter_ips_replaced
uint16_t counter_ips_replaced
Definition: decode.c:952
DecodeThreadVars_::counter_gre
uint16_t counter_gre
Definition: decode.h:968
ACTION_DROP
#define ACTION_DROP
Definition: action-globals.h:30
DecodeThreadVars_::counter_esp
uint16_t counter_esp
Definition: decode.h:965
Packet_::ext_pkt
uint8_t * ext_pkt
Definition: decode.h:604
PKT_DROP_REASON_NFQ_ERROR
@ PKT_DROP_REASON_NFQ_ERROR
Definition: decode.h:389
DecodeThreadVars_::counter_defrag_ipv6_reassembled
uint16_t counter_defrag_ipv6_reassembled
Definition: decode.h:987
DecodeThreadVars_::counter_udp
uint16_t counter_udp
Definition: decode.h:955
GENERIC_TOO_MANY_LAYERS
@ GENERIC_TOO_MANY_LAYERS
Definition: decode-events.h:221
Packet_::ttype
enum PacketTunnelType ttype
Definition: decode.h:534
PacketUpdateEngineEventCounters
void PacketUpdateEngineEventCounters(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
Definition: decode.c:210
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
CaptureStats_::counter_drop_reason
uint16_t counter_drop_reason[PKT_DROP_REASON_MAX]
Definition: decode.c:954
DecodeThreadVars_::counter_flow_memcap_eps
ExceptionPolicyCounters counter_flow_memcap_eps
Definition: decode.h:992
FatalError
#define FatalError(...)
Definition: util-debug.h:502
decode-geneve.h
PKT_SRC_DEFRAG
@ PKT_SRC_DEFRAG
Definition: decode.h:60
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
DecodeThreadVars_::counter_ipv4
uint16_t counter_ipv4
Definition: decode.h:949
PACKET_PROFILING_START
#define PACKET_PROFILING_START(p)
Definition: util-profiling.h:73
util-validate.h
PacketGetFromAlloc
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
Definition: decode.c:229
defrag_memcap_eps_stats
ExceptionPolicyStatsSetts defrag_memcap_eps_stats
Definition: decode.c:85
PKT_SRC_DECODER_VXLAN
@ PKT_SRC_DECODER_VXLAN
Definition: decode.h:63
StatsAddUI64
void StatsAddUI64(ThreadVars *tv, uint16_t id, uint64_t x)
Adds a value of type uint64_t to the local counter.
Definition: counters.c:146
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
PACKET_ALERT_MAX
#define PACKET_ALERT_MAX
Definition: decode.h:270
Packet_::root
struct Packet_ * root
Definition: decode.h:642
DecodeThreadVars_::counter_pppoe
uint16_t counter_pppoe
Definition: decode.h:975
DecodeThreadVars_::counter_mpls
uint16_t counter_mpls
Definition: decode.h:977
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
OutputFlowLogThreadDeinit
TmEcode OutputFlowLogThreadDeinit(ThreadVars *tv, void *thread_data)
Definition: output-flow.c:163
PKT_SRC_DETECT_RELOAD_FLUSH
@ PKT_SRC_DETECT_RELOAD_FLUSH
Definition: decode.h:64
SCFree
#define SCFree(p)
Definition: util-mem.h:61
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:933
MAX_PAYLOAD_SIZE
#define MAX_PAYLOAD_SIZE
Definition: decode.h:690
ExceptionPolicyStatsSetts_::valid_settings_ips
bool valid_settings_ips[EXCEPTION_POLICY_MAX]
Definition: util-exception-policy-types.h:51
AppLayerDestroyCtxThread
void AppLayerDestroyCtxThread(AppLayerThreadCtx *app_tctx)
Destroys the context created by AppLayerGetCtxThread().
Definition: app-layer.c:1080
Packet_::recursion_level
uint8_t recursion_level
Definition: decode.h:513
DecodeThreadVars_::output_flow_thread_data
void * output_flow_thread_data
Definition: decode.h:1017
DecodeThreadVars_::counter_geneve
uint16_t counter_geneve
Definition: decode.h:967
DecodeThreadVars_::counter_max_mac_addrs_dst
uint16_t counter_max_mac_addrs_dst
Definition: decode.h:943
DecodeThreadVarsAlloc
DecodeThreadVars * DecodeThreadVarsAlloc(ThreadVars *tv)
Alloc and setup DecodeThreadVars.
Definition: decode.c:769
DecodeThreadVars_::counter_defrag_max_hit
uint16_t counter_defrag_max_hit
Definition: decode.h:988
HashTableInit
HashTable * HashTableInit(uint32_t size, uint32_t(*Hash)(struct HashTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
Definition: util-hash.c:35
PacketSetData
int PacketSetData(Packet *p, const uint8_t *pktdata, uint32_t pktlen)
Set data for Packet and set length when zero copy is used.
Definition: decode.c:807
PacketPoolGetPacket
Packet * PacketPoolGetPacket(void)
Get a new packet from the packet pool.
Definition: tmqh-packetpool.c:127
DecodeThreadVars_::counter_vlan_qinqinq
uint16_t counter_vlan_qinqinq
Definition: decode.h:971
GET_PKT_DIRECT_DATA
#define GET_PKT_DIRECT_DATA(p)
Definition: decode.h:214
DecodeThreadVars_::counter_null
uint16_t counter_null
Definition: decode.h:963
t_capture_stats
thread_local CaptureStats t_capture_stats
Definition: decode.c:957
DecodeThreadVars_::counter_icmpv6
uint16_t counter_icmpv6
Definition: decode.h:957
EngineModeIsIPS
int EngineModeIsIPS(void)
Definition: suricata.c:231
defrag-hash.h
Packet_::drop_reason
uint8_t drop_reason
Definition: decode.h:636
Address_::family
char family
Definition: decode.h:117
PKT_SRC_DECODER_GRE
@ PKT_SRC_DECODER_GRE
Definition: decode.h:56
ENGINE_SET_INVALID_EVENT
#define ENGINE_SET_INVALID_EVENT(p, e)
Definition: decode.h:1152
PacketAlert_
Definition: decode.h:247
DecodeGeneveConfig
void DecodeGeneveConfig(void)
Definition: decode-geneve.c:128
DecodeThreadVars_::counter_flow_memcap
uint16_t counter_flow_memcap
Definition: decode.h:991
DecodeThreadVars_::counter_defrag_ipv6_fragments
uint16_t counter_defrag_ipv6_fragments
Definition: decode.h:986
PacketTunnelRoot
@ PacketTunnelRoot
Definition: decode.h:396
packet_alert_max
uint16_t packet_alert_max
Definition: decode.c:81
Packet_::vlan_id
uint16_t vlan_id[VLAN_MAX_LAYERS]
Definition: decode.h:515
likely
#define likely(expr)
Definition: util-optimize.h:32
StatsRegisterAvgCounter
uint16_t StatsRegisterAvgCounter(const char *name, struct ThreadVars_ *tv)
Registers a counter, whose value holds the average of all the values assigned to it.
Definition: counters.c:991
PacketDefragPktSetupParent
void PacketDefragPktSetupParent(Packet *parent)
inform defrag "parent" that a pseudo packet is now associated to it.
Definition: decode.c:483
DecodeThreadVars_::counter_tcp_syn
uint16_t counter_tcp_syn
Definition: decode.h:952
PacketTunnelPktSetup
Packet * PacketTunnelPktSetup(ThreadVars *tv, DecodeThreadVars *dtv, Packet *parent, const uint8_t *pkt, uint32_t len, enum DecodeTunnelProto proto)
Setup a pseudo packet (tunnel)
Definition: decode.c:364
stats_decoder_events
bool stats_decoder_events
Definition: counters.c:101
flow.h
PKT_DROP_REASON_STREAM_MIDSTREAM
@ PKT_DROP_REASON_STREAM_MIDSTREAM
Definition: decode.h:387
DecodeIPV4
int DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
Definition: decode-ipv4.c:520
PacketInit
void PacketInit(Packet *p)
Initialize a packet structure for use.
Definition: packet.c:62
ExceptionPolicy
ExceptionPolicy
Definition: util-exception-policy-types.h:25
StatsRegisterCounter
uint16_t StatsRegisterCounter(const char *name, struct ThreadVars_ *tv)
Registers a normal, unqualified counter.
Definition: counters.c:971
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
DecodeThreadVars_::counter_flow_get_used_eval_reject
uint16_t counter_flow_get_used_eval_reject
Definition: decode.h:1004
DecodeVLAN
int DecodeVLAN(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Definition: decode-vlan.c:54
FLOW_PKT_TOSERVER_FIRST
#define FLOW_PKT_TOSERVER_FIRST
Definition: flow.h:232
DefragGetMemcapExceptionPolicy
enum ExceptionPolicy DefragGetMemcapExceptionPolicy(void)
Definition: defrag-hash.c:78
SCMutex
#define SCMutex
Definition: threads-debug.h:114
PacketGetFromQueueOrAlloc
Packet * PacketGetFromQueueOrAlloc(void)
Get a packet. We try to get a packet from the packetpool first, but if that is empty we alloc a packe...
Definition: decode.c:264
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:102
DecodeEthernet
int DecodeEthernet(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Definition: decode-ethernet.c:42
PKT_DROP_REASON_FLOW_DROP
@ PKT_DROP_REASON_FLOW_DROP
Definition: decode.h:380
WARN_UNUSED
#define WARN_UNUSED
Definition: suricata-common.h:403
PKT_IS_INVALID
#define PKT_IS_INVALID
Definition: decode.h:1287
DecodeUpdatePacketCounters
void DecodeUpdatePacketCounters(ThreadVars *tv, const DecodeThreadVars *dtv, const Packet *p)
Definition: decode.c:735
DecodeThreadVars_::counter_engine_events
uint16_t counter_engine_events[DECODE_EVENT_MAX]
Definition: decode.h:1013
output.h
DECODE_EVENT_MAX
@ DECODE_EVENT_MAX
Definition: decode-events.h:301
app-layer.h
PKT_DROP_REASON_DECODE_ERROR
@ PKT_DROP_REASON_DECODE_ERROR
Definition: decode.h:376
DecodeThreadVars_::counter_defrag_ipv4_fragments
uint16_t counter_defrag_ipv4_fragments
Definition: decode.h:984
PacketEngineEvents_::cnt
uint8_t cnt
Definition: decode.h:292