suricata
decode.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2022 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  */
23 
24 #ifndef __DECODE_H__
25 #define __DECODE_H__
26 
27 //#define DBG_THREADS
28 #define COUNTERS
29 
30 #include "suricata-common.h"
31 #include "suricata-plugin.h"
32 #include "threadvars.h"
33 #include "util-debug.h"
34 #include "decode-events.h"
35 #include "flow-worker.h"
36 
37 #ifdef HAVE_NAPATECH
38 #include "util-napatech.h"
39 #endif /* HAVE_NAPATECH */
40 
41 
42 typedef enum {
49 
50 enum PktSrcEnum {
63 };
64 
65 #include "source-nflog.h"
66 #include "source-nfq.h"
67 #include "source-ipfw.h"
68 #include "source-pcap.h"
69 #include "source-af-packet.h"
70 #include "source-netmap.h"
71 #include "source-windivert.h"
72 #ifdef HAVE_DPDK
73 #include "source-dpdk.h"
74 #endif
75 #ifdef HAVE_PF_RING_FLOW_OFFLOAD
76 #include "source-pfring.h"
77 #endif
78 
79 #include "action-globals.h"
80 
81 #include "decode-erspan.h"
82 #include "decode-ethernet.h"
83 #include "decode-chdlc.h"
84 #include "decode-gre.h"
85 #include "decode-geneve.h"
86 #include "decode-ppp.h"
87 #include "decode-pppoe.h"
88 #include "decode-sll.h"
89 #include "decode-ipv4.h"
90 #include "decode-ipv6.h"
91 #include "decode-icmpv4.h"
92 #include "decode-icmpv6.h"
93 #include "decode-tcp.h"
94 #include "decode-udp.h"
95 #include "decode-sctp.h"
96 #include "decode-esp.h"
97 #include "decode-raw.h"
98 #include "decode-null.h"
99 #include "decode-vlan.h"
100 #include "decode-vntag.h"
101 #include "decode-vxlan.h"
102 #include "decode-mpls.h"
103 #include "decode-nsh.h"
104 
105 #include "detect-reference.h"
106 
107 #include "app-layer-protos.h"
108 
109 /* forward declarations */
110 struct DetectionEngineThreadCtx_;
112 
113 struct PktPool_;
114 
115 /* declare these here as they are called from the
116  * PACKET_RECYCLE and PACKET_CLEANUP macro's. */
120 
121 /* Address */
122 typedef struct Address_ {
123  char family;
124  union {
125  uint32_t address_un_data32[4]; /* type-specific field */
126  uint16_t address_un_data16[8]; /* type-specific field */
127  uint8_t address_un_data8[16]; /* type-specific field */
128  struct in6_addr address_un_in6;
131 
132 #define addr_data32 address.address_un_data32
133 #define addr_data16 address.address_un_data16
134 #define addr_data8 address.address_un_data8
135 #define addr_in6addr address.address_un_in6
136 
137 #define COPY_ADDRESS(a, b) do { \
138  (b)->family = (a)->family; \
139  (b)->addr_data32[0] = (a)->addr_data32[0]; \
140  (b)->addr_data32[1] = (a)->addr_data32[1]; \
141  (b)->addr_data32[2] = (a)->addr_data32[2]; \
142  (b)->addr_data32[3] = (a)->addr_data32[3]; \
143  } while (0)
144 
145 /* Set the IPv4 addresses into the Addrs of the Packet.
146  * Make sure p->ip4h is initialized and validated.
147  *
148  * We set the rest of the struct to 0 so we can
149  * prevent using memset. */
150 #define SET_IPV4_SRC_ADDR(p, a) do { \
151  (a)->family = AF_INET; \
152  (a)->addr_data32[0] = (uint32_t)(p)->ip4h->s_ip_src.s_addr; \
153  (a)->addr_data32[1] = 0; \
154  (a)->addr_data32[2] = 0; \
155  (a)->addr_data32[3] = 0; \
156  } while (0)
157 
158 #define SET_IPV4_DST_ADDR(p, a) do { \
159  (a)->family = AF_INET; \
160  (a)->addr_data32[0] = (uint32_t)(p)->ip4h->s_ip_dst.s_addr; \
161  (a)->addr_data32[1] = 0; \
162  (a)->addr_data32[2] = 0; \
163  (a)->addr_data32[3] = 0; \
164  } while (0)
165 
166 /* clear the address structure by setting all fields to 0 */
167 #define CLEAR_ADDR(a) do { \
168  (a)->family = 0; \
169  (a)->addr_data32[0] = 0; \
170  (a)->addr_data32[1] = 0; \
171  (a)->addr_data32[2] = 0; \
172  (a)->addr_data32[3] = 0; \
173  } while (0)
174 
175 /* Set the IPv6 addresses into the Addrs of the Packet.
176  * Make sure p->ip6h is initialized and validated. */
177 #define SET_IPV6_SRC_ADDR(p, a) do { \
178  (a)->family = AF_INET6; \
179  (a)->addr_data32[0] = (p)->ip6h->s_ip6_src[0]; \
180  (a)->addr_data32[1] = (p)->ip6h->s_ip6_src[1]; \
181  (a)->addr_data32[2] = (p)->ip6h->s_ip6_src[2]; \
182  (a)->addr_data32[3] = (p)->ip6h->s_ip6_src[3]; \
183  } while (0)
184 
185 #define SET_IPV6_DST_ADDR(p, a) do { \
186  (a)->family = AF_INET6; \
187  (a)->addr_data32[0] = (p)->ip6h->s_ip6_dst[0]; \
188  (a)->addr_data32[1] = (p)->ip6h->s_ip6_dst[1]; \
189  (a)->addr_data32[2] = (p)->ip6h->s_ip6_dst[2]; \
190  (a)->addr_data32[3] = (p)->ip6h->s_ip6_dst[3]; \
191  } while (0)
192 
193 /* Set the TCP ports into the Ports of the Packet.
194  * Make sure p->tcph is initialized and validated. */
195 #define SET_TCP_SRC_PORT(pkt, prt) do { \
196  SET_PORT(TCP_GET_SRC_PORT((pkt)), *(prt)); \
197  } while (0)
198 
199 #define SET_TCP_DST_PORT(pkt, prt) do { \
200  SET_PORT(TCP_GET_DST_PORT((pkt)), *(prt)); \
201  } while (0)
202 
203 /* Set the UDP ports into the Ports of the Packet.
204  * Make sure p->udph is initialized and validated. */
205 #define SET_UDP_SRC_PORT(pkt, prt) do { \
206  SET_PORT(UDP_GET_SRC_PORT((pkt)), *(prt)); \
207  } while (0)
208 #define SET_UDP_DST_PORT(pkt, prt) do { \
209  SET_PORT(UDP_GET_DST_PORT((pkt)), *(prt)); \
210  } while (0)
211 
212 /* Set the SCTP ports into the Ports of the Packet.
213  * Make sure p->sctph is initialized and validated. */
214 #define SET_SCTP_SRC_PORT(pkt, prt) do { \
215  SET_PORT(SCTP_GET_SRC_PORT((pkt)), *(prt)); \
216  } while (0)
217 
218 #define SET_SCTP_DST_PORT(pkt, prt) do { \
219  SET_PORT(SCTP_GET_DST_PORT((pkt)), *(prt)); \
220  } while (0)
221 
222 
223 #define GET_IPV4_SRC_ADDR_U32(p) ((p)->src.addr_data32[0])
224 #define GET_IPV4_DST_ADDR_U32(p) ((p)->dst.addr_data32[0])
225 #define GET_IPV4_SRC_ADDR_PTR(p) ((p)->src.addr_data32)
226 #define GET_IPV4_DST_ADDR_PTR(p) ((p)->dst.addr_data32)
227 
228 #define GET_IPV6_SRC_IN6ADDR(p) ((p)->src.addr_in6addr)
229 #define GET_IPV6_DST_IN6ADDR(p) ((p)->dst.addr_in6addr)
230 #define GET_IPV6_SRC_ADDR(p) ((p)->src.addr_data32)
231 #define GET_IPV6_DST_ADDR(p) ((p)->dst.addr_data32)
232 #define GET_TCP_SRC_PORT(p) ((p)->sp)
233 #define GET_TCP_DST_PORT(p) ((p)->dp)
234 
235 #define GET_PKT_LEN(p) ((p)->pktlen)
236 #define GET_PKT_DATA(p) ((((p)->ext_pkt) == NULL ) ? (uint8_t *)((p) + 1) : (p)->ext_pkt)
237 #define GET_PKT_DIRECT_DATA(p) (uint8_t *)((p) + 1)
238 #define GET_PKT_DIRECT_MAX_SIZE(p) (default_packet_size)
239 
240 #define SET_PKT_LEN(p, len) do { \
241  (p)->pktlen = (len); \
242  } while (0)
243 
244 
245 /* Port is just a uint16_t */
246 typedef uint16_t Port;
247 #define SET_PORT(v, p) ((p) = (v))
248 #define COPY_PORT(a,b) ((b) = (a))
249 
250 #define CMP_ADDR(a1, a2) \
251  (((a1)->addr_data32[3] == (a2)->addr_data32[3] && \
252  (a1)->addr_data32[2] == (a2)->addr_data32[2] && \
253  (a1)->addr_data32[1] == (a2)->addr_data32[1] && \
254  (a1)->addr_data32[0] == (a2)->addr_data32[0]))
255 #define CMP_PORT(p1, p2) \
256  ((p1) == (p2))
257 
258 /*Given a packet pkt offset to the start of the ip header in a packet
259  *We determine the ip version. */
260 #define IP_GET_RAW_VER(pkt) ((((pkt)[0] & 0xf0) >> 4))
261 
262 #define PKT_IS_IPV4(p) (((p)->ip4h != NULL))
263 #define PKT_IS_IPV6(p) (((p)->ip6h != NULL))
264 #define PKT_IS_TCP(p) (((p)->tcph != NULL))
265 #define PKT_IS_UDP(p) (((p)->udph != NULL))
266 #define PKT_IS_ICMPV4(p) (((p)->icmpv4h != NULL))
267 #define PKT_IS_ICMPV6(p) (((p)->icmpv6h != NULL))
268 #define PKT_IS_TOSERVER(p) (((p)->flowflags & FLOW_PKT_TOSERVER))
269 #define PKT_IS_TOCLIENT(p) (((p)->flowflags & FLOW_PKT_TOCLIENT))
270 
271 #define IPH_IS_VALID(p) (PKT_IS_IPV4((p)) || PKT_IS_IPV6((p)))
272 
273 /* Retrieve proto regardless of IP version */
274 #define IP_GET_IPPROTO(p) \
275  (p->proto ? p->proto : \
276  (PKT_IS_IPV4((p))? IPV4_GET_IPPROTO((p)) : (PKT_IS_IPV6((p))? IPV6_GET_L4PROTO((p)) : 0)))
277 
278 /* structure to store the sids/gids/etc the detection engine
279  * found in this packet */
280 typedef struct PacketAlert_ {
281  SigIntId num; /* Internal num, used for sorting */
282  uint8_t action; /* Internal num, used for thresholding */
283  uint8_t flags;
284  const struct Signature_ *s;
285  uint64_t tx_id; /* Used for sorting */
286  int64_t frame_id;
288 
289 /* flag to indicate the rule action (drop/pass) needs to be applied to the flow */
290 #define PACKET_ALERT_FLAG_APPLY_ACTION_TO_FLOW 0x1
291 /** alert was generated based on state */
292 #define PACKET_ALERT_FLAG_STATE_MATCH 0x02
293 /** alert was generated based on stream */
294 #define PACKET_ALERT_FLAG_STREAM_MATCH 0x04
295 /** alert is in a tx, tx_id set */
296 #define PACKET_ALERT_FLAG_TX 0x08
297 /** action was changed by rate_filter */
298 #define PACKET_ALERT_RATE_FILTER_MODIFIED 0x10
299 /** alert is in a frame, frame_id set */
300 #define PACKET_ALERT_FLAG_FRAME 0x20
301 
302 extern uint16_t packet_alert_max;
303 #define PACKET_ALERT_MAX 15
304 
305 typedef struct PacketAlerts_ {
306  uint16_t cnt;
307  uint16_t discarded;
308  uint16_t suppressed;
310  /* single pa used when we're dropping,
311  * so we can log it out in the drop log. */
314 
316 
317 void PacketAlertFree(PacketAlert *pa);
318 
319 /** number of decoder events we support per packet. Power of 2 minus 1
320  * for memory layout */
321 #define PACKET_ENGINE_EVENT_MAX 15
322 
323 /** data structure to store decoder, defrag and stream events */
324 typedef struct PacketEngineEvents_ {
325  uint8_t cnt; /**< number of events */
326  uint8_t events[PACKET_ENGINE_EVENT_MAX]; /**< array of events */
328 
329 typedef struct PktVar_ {
330  uint32_t id;
331  struct PktVar_ *next; /* right now just implement this as a list,
332  * in the long run we have thing of something
333  * faster. */
334  uint16_t key_len;
335  uint16_t value_len;
336  uint8_t *key;
337  uint8_t *value;
339 
340 #ifdef PROFILING
341 
342 /** \brief Per TMM stats storage */
343 typedef struct PktProfilingTmmData_ {
344  uint64_t ticks_start;
345  uint64_t ticks_end;
346 #ifdef PROFILE_LOCKING
347  uint64_t mutex_lock_cnt;
348  uint64_t mutex_lock_wait_ticks;
349  uint64_t mutex_lock_contention;
350  uint64_t spin_lock_cnt;
351  uint64_t spin_lock_wait_ticks;
352  uint64_t spin_lock_contention;
353  uint64_t rww_lock_cnt;
354  uint64_t rww_lock_wait_ticks;
355  uint64_t rww_lock_contention;
356  uint64_t rwr_lock_cnt;
357  uint64_t rwr_lock_wait_ticks;
358  uint64_t rwr_lock_contention;
359 #endif
361 
362 typedef struct PktProfilingData_ {
363  uint64_t ticks_start;
364  uint64_t ticks_end;
366 
367 typedef struct PktProfilingDetectData_ {
368  uint64_t ticks_start;
369  uint64_t ticks_end;
370  uint64_t ticks_spent;
372 
373 typedef struct PktProfilingAppData_ {
374  uint64_t ticks_spent;
376 
377 typedef struct PktProfilingLoggerData_ {
378  uint64_t ticks_start;
379  uint64_t ticks_end;
380  uint64_t ticks_spent;
382 
384  uint64_t ticks_spent;
386 
389  uint32_t size; /**< array size */
391 
392 /** \brief Per pkt stats storage */
393 typedef struct PktProfiling_ {
394  uint64_t ticks_start;
395  uint64_t ticks_end;
396 
402  uint64_t proto_detect;
404 
405 #endif /* PROFILING */
406 
419  PKT_DROP_REASON_RULES_THRESHOLD, /**< detection_filter in action */
420 };
421 
422 /* forward declaration since Packet struct definition requires this */
423 struct PacketQueue_;
424 
425 /* sizes of the members:
426  * src: 17 bytes
427  * dst: 17 bytes
428  * sp/type: 1 byte
429  * dp/code: 1 byte
430  * proto: 1 byte
431  * recurs: 1 byte
432  *
433  * sum of above: 38 bytes
434  *
435  * flow ptr: 4/8 bytes
436  * flags: 1 byte
437  * flowflags: 1 byte
438  *
439  * sum of above 44/48 bytes
440  */
441 typedef struct Packet_
442 {
443  /* Addresses, Ports and protocol
444  * these are on top so we can use
445  * the Packet as a hash key */
448  union {
450  // icmp type and code of this packet
451  struct {
452  uint8_t type;
453  uint8_t code;
455  };
456  union {
458  // icmp type and code of the expected counterpart (for flows)
459  struct {
460  uint8_t type;
461  uint8_t code;
463  };
464  uint8_t proto;
465  /* make sure we can't be attacked on when the tunneled packet
466  * has the exact same tuple as the lower levels */
468 
469  uint16_t vlan_id[2];
470  uint8_t vlan_idx;
471 
472  /* flow */
473  uint8_t flowflags;
474  /* coccinelle: Packet:flowflags:FLOW_PKT_ */
475 
476  /* Pkt Flags */
477  uint32_t flags;
478 
479  struct Flow_ *flow;
480 
481  /* raw hash value for looking up the flow, will need to modulated to the
482  * hash size still */
483  uint32_t flow_hash;
484 
485  struct timeval ts;
486 
487  union {
488  /* nfq stuff */
489 #ifdef HAVE_NFLOG
490  NFLOGPacketVars nflog_v;
491 #endif /* HAVE_NFLOG */
492 #ifdef NFQ
494 #endif /* NFQ */
495 #ifdef IPFW
497 #endif /* IPFW */
498 #ifdef AF_PACKET
499  AFPPacketVars afp_v;
500 #endif
501 #ifdef HAVE_NETMAP
502  NetmapPacketVars netmap_v;
503 #endif
504 #ifdef HAVE_PFRING
505 #ifdef HAVE_PF_RING_FLOW_OFFLOAD
506  PfringPacketVars pfring_v;
507 #endif
508 #endif
509 #ifdef WINDIVERT
510  WinDivertPacketVars windivert_v;
511 #endif /* WINDIVERT */
512 #ifdef HAVE_DPDK
513  DPDKPacketVars dpdk_v;
514 #endif
515 
516  /* A chunk of memory that a plugin can use for its packet vars. */
518 
519  /** libpcap vars: shared by Pcap Live mode and Pcap File mode */
521  };
522 
523  /** The release function for packet structure and data */
524  void (*ReleasePacket)(struct Packet_ *);
525  /** The function triggering bypass the flow in the capture method.
526  * Return 1 for success and 0 on error */
527  int (*BypassPacketsFlow)(struct Packet_ *);
528 
529  /* pkt vars */
531 
532  /* header pointers */
533  EthernetHdr *ethh;
534 
535  /* Checksum for IP packets. */
537  /* Check sum for TCP, UDP or ICMP packets */
539 
541 
543 
544  /* IPv4 and IPv6 are mutually exclusive */
545  union {
547  struct {
550  };
551  };
552  /* Can only be one of TCP, UDP, ICMP at any given time */
553  union {
558 #define tcpvars l4vars.tcpvars
559 #define icmpv4vars l4vars.icmpv4vars
560 #define icmpv6vars l4vars.icmpv6vars
561 
562  TCPHdr *tcph;
563 
564  UDPHdr *udph;
565 
566  SCTPHdr *sctph;
567 
568  ESPHdr *esph;
569 
570  ICMPV4Hdr *icmpv4h;
571 
573 
574  PPPHdr *ppph;
576  PPPOEDiscoveryHdr *pppoedh;
577 
578  GREHdr *greh;
579 
580  /* ptr to the payload of the packet
581  * with it's length. */
582  uint8_t *payload;
583  uint16_t payload_len;
584 
585  /* IPS action to take */
586  uint8_t action;
587 
588  uint8_t pkt_src;
589 
590  /* storage: set to pointer to heap and extended via allocation if necessary */
591  uint32_t pktlen;
592  uint8_t *ext_pkt;
593 
594  /* Incoming interface */
596 
598 
599  struct Host_ *host_src;
600  struct Host_ *host_dst;
601 
602  /** packet number in the pcap file, matches wireshark */
603  uint64_t pcap_cnt;
604 
605 
606  /* engine events */
608 
610 
611  /* double linked list ptrs */
612  struct Packet_ *next;
613  struct Packet_ *prev;
614 
615  /** data linktype in host order */
616  int datalink;
617 
618  /* count decoded layers of packet : too many layers
619  * cause issues with performance and stability (stack exhaustion)
620  */
622 
623  /* enum PacketDropReason::PKT_DROP_REASON_* as uint8_t for compactness */
624  uint8_t drop_reason;
625 
626  /* tunnel/encapsulation handling */
627  struct Packet_ *root; /* in case of tunnel this is a ptr
628  * to the 'real' packet, the one we
629  * need to set the verdict on --
630  * It should always point to the lowest
631  * packet in a encapsulated packet */
632 
633  /** mutex to protect access to:
634  * - tunnel_rtv_cnt
635  * - tunnel_tpr_cnt
636  */
638  /* ready to set verdict counter, only set in root */
639  uint16_t tunnel_rtv_cnt;
640  /* tunnel packet ref count */
641  uint16_t tunnel_tpr_cnt;
642 
643  /** tenant id for this packet, if any. If 0 then no tenant was assigned. */
644  uint32_t tenant_id;
645 
646  /* The Packet pool from which this packet was allocated. Used when returning
647  * the packet to its owner's stack. If NULL, then allocated with malloc.
648  */
649  struct PktPool_ *pool;
650 
651 #ifdef PROFILING
653 #endif
654 #ifdef HAVE_NAPATECH
656 #endif
658 
659 /** highest mtu of the interfaces we monitor */
660 extern int g_default_mtu;
661 #define DEFAULT_MTU 1500
662 #define MINIMUM_MTU 68 /**< ipv4 minimum: rfc791 */
663 
664 #define DEFAULT_PACKET_SIZE (DEFAULT_MTU + ETHERNET_HEADER_LEN)
665 /* storage: maximum ip packet size + link header */
666 #define MAX_PAYLOAD_SIZE (IPV6_HEADER_LEN + 65536 + 28)
667 extern uint32_t default_packet_size;
668 #define SIZE_OF_PACKET (default_packet_size + sizeof(Packet))
669 
670 /** \brief Structure to hold thread specific data for all decode modules */
671 typedef struct DecodeThreadVars_
672 {
673  /** Specific context for udp protocol detection (here atm) */
675 
676  /** stats/counters */
677  uint16_t counter_pkts;
678  uint16_t counter_bytes;
683 
684  uint16_t counter_invalid;
685 
686  uint16_t counter_eth;
687  uint16_t counter_chdlc;
688  uint16_t counter_ipv4;
689  uint16_t counter_ipv6;
690  uint16_t counter_tcp;
691  uint16_t counter_udp;
692  uint16_t counter_icmpv4;
693  uint16_t counter_icmpv6;
694 
695  uint16_t counter_sll;
696  uint16_t counter_raw;
697  uint16_t counter_null;
698  uint16_t counter_sctp;
699  uint16_t counter_esp;
700  uint16_t counter_ppp;
701  uint16_t counter_geneve;
702  uint16_t counter_gre;
703  uint16_t counter_vlan;
705  uint16_t counter_vxlan;
706  uint16_t counter_vntag;
708  uint16_t counter_pppoe;
709  uint16_t counter_teredo;
710  uint16_t counter_mpls;
713  uint16_t counter_erspan;
714  uint16_t counter_nsh;
715 
716  /** frag stats - defrag runs in the context of the decoder. */
724 
726 
740 
745 
747 
748  /* thread data for flow logging api: only used at forced
749  * flow recycle during lookups */
751 
753 
754 typedef struct CaptureStats_ {
755 
760 
762 
763 void CaptureStatsUpdate(ThreadVars *tv, CaptureStats *s, const Packet *p);
765 
766 #define PACKET_CLEAR_L4VARS(p) do { \
767  memset(&(p)->l4vars, 0x00, sizeof((p)->l4vars)); \
768  } while (0)
769 
770 /**
771  * \brief reset these to -1(indicates that the packet is fresh from the queue)
772  */
773 #define PACKET_RESET_CHECKSUMS(p) do { \
774  (p)->level3_comp_csum = -1; \
775  (p)->level4_comp_csum = -1; \
776  } while (0)
777 
778 /* if p uses extended data, free them */
779 #define PACKET_FREE_EXTDATA(p) do { \
780  if ((p)->ext_pkt) { \
781  if (!((p)->flags & PKT_ZERO_COPY)) { \
782  SCFree((p)->ext_pkt); \
783  } \
784  (p)->ext_pkt = NULL; \
785  } \
786  } while(0)
787 
788 /**
789  * \brief Initialize a packet structure for use.
790  */
791 #define PACKET_INITIALIZE(p) \
792  { \
793  SCMutexInit(&(p)->tunnel_mutex, NULL); \
794  (p)->alerts.alerts = PacketAlertCreate(); \
795  PACKET_RESET_CHECKSUMS((p)); \
796  (p)->livedev = NULL; \
797  }
798 
799 #define PACKET_RELEASE_REFS(p) do { \
800  FlowDeReference(&((p)->flow)); \
801  HostDeReference(&((p)->host_src)); \
802  HostDeReference(&((p)->host_dst)); \
803  } while (0)
804 
805 /**
806  * \brief Recycle a packet structure for reuse.
807  */
808 #define PACKET_REINIT(p) \
809  do { \
810  CLEAR_ADDR(&(p)->src); \
811  CLEAR_ADDR(&(p)->dst); \
812  (p)->sp = 0; \
813  (p)->dp = 0; \
814  (p)->proto = 0; \
815  (p)->recursion_level = 0; \
816  PACKET_FREE_EXTDATA((p)); \
817  (p)->flags = (p)->flags & PKT_ALLOC; \
818  (p)->flowflags = 0; \
819  (p)->pkt_src = 0; \
820  (p)->vlan_id[0] = 0; \
821  (p)->vlan_id[1] = 0; \
822  (p)->vlan_idx = 0; \
823  (p)->ts.tv_sec = 0; \
824  (p)->ts.tv_usec = 0; \
825  (p)->datalink = 0; \
826  (p)->drop_reason = 0; \
827  (p)->action = 0; \
828  if ((p)->pktvar != NULL) { \
829  PktVarFree((p)->pktvar); \
830  (p)->pktvar = NULL; \
831  } \
832  (p)->ethh = NULL; \
833  if ((p)->ip4h != NULL) { \
834  CLEAR_IPV4_PACKET((p)); \
835  } \
836  if ((p)->ip6h != NULL) { \
837  CLEAR_IPV6_PACKET((p)); \
838  } \
839  if ((p)->tcph != NULL) { \
840  CLEAR_TCP_PACKET((p)); \
841  } \
842  if ((p)->udph != NULL) { \
843  CLEAR_UDP_PACKET((p)); \
844  } \
845  if ((p)->sctph != NULL) { \
846  CLEAR_SCTP_PACKET((p)); \
847  } \
848  if ((p)->esph != NULL) { \
849  CLEAR_ESP_PACKET((p)); \
850  } \
851  if ((p)->icmpv4h != NULL) { \
852  CLEAR_ICMPV4_PACKET((p)); \
853  } \
854  if ((p)->icmpv6h != NULL) { \
855  CLEAR_ICMPV6_PACKET((p)); \
856  } \
857  (p)->ppph = NULL; \
858  (p)->pppoesh = NULL; \
859  (p)->pppoedh = NULL; \
860  (p)->greh = NULL; \
861  (p)->payload = NULL; \
862  (p)->payload_len = 0; \
863  (p)->BypassPacketsFlow = NULL; \
864  (p)->pktlen = 0; \
865  (p)->alerts.cnt = 0; \
866  (p)->alerts.discarded = 0; \
867  (p)->alerts.suppressed = 0; \
868  (p)->alerts.drop.action = 0; \
869  (p)->pcap_cnt = 0; \
870  (p)->tunnel_rtv_cnt = 0; \
871  (p)->tunnel_tpr_cnt = 0; \
872  (p)->events.cnt = 0; \
873  AppLayerDecoderEventsResetEvents((p)->app_layer_events); \
874  (p)->next = NULL; \
875  (p)->prev = NULL; \
876  (p)->root = NULL; \
877  (p)->livedev = NULL; \
878  PACKET_RESET_CHECKSUMS((p)); \
879  PACKET_PROFILING_RESET((p)); \
880  p->tenant_id = 0; \
881  p->nb_decoded_layers = 0; \
882  } while (0)
883 
884 #define PACKET_RECYCLE(p) do { \
885  PACKET_RELEASE_REFS((p)); \
886  PACKET_REINIT((p)); \
887  } while (0)
888 
889 /**
890  * \brief Cleanup a packet so that we can free it. No memset needed..
891  */
892 #define PACKET_DESTRUCTOR(p) \
893  do { \
894  PACKET_RELEASE_REFS((p)); \
895  if ((p)->pktvar != NULL) { \
896  PktVarFree((p)->pktvar); \
897  } \
898  PacketAlertFree((p)->alerts.alerts); \
899  PACKET_FREE_EXTDATA((p)); \
900  SCMutexDestroy(&(p)->tunnel_mutex); \
901  AppLayerDecoderEventsFreeEvents(&(p)->app_layer_events); \
902  PACKET_PROFILING_RESET((p)); \
903  } while (0)
904 
905 /* macro's for setting the action
906  * handle the case of a root packet
907  * for tunnels */
908 
909 #define PACKET_SET_ACTION(p, a) (p)->action = (a)
910 
911 static inline void PacketSetAction(Packet *p, const uint8_t a)
912 {
913  if (likely(p->root == NULL)) {
914  PACKET_SET_ACTION(p, a);
915  } else {
916  PACKET_SET_ACTION(p->root, a);
917  }
918 }
919 
920 #define PACKET_ALERT(p) PACKET_SET_ACTION(p, ACTION_ALERT)
921 
922 #define PACKET_ACCEPT(p) PACKET_SET_ACTION(p, ACTION_ACCEPT)
923 
924 #define PACKET_REJECT(p) PACKET_SET_ACTION(p, (ACTION_REJECT|ACTION_DROP))
925 
926 #define PACKET_REJECT_DST(p) PACKET_SET_ACTION(p, (ACTION_REJECT_DST|ACTION_DROP))
927 
928 #define PACKET_REJECT_BOTH(p) PACKET_SET_ACTION(p, (ACTION_REJECT_BOTH|ACTION_DROP))
929 
930 #define PACKET_PASS(p) PACKET_SET_ACTION(p, ACTION_PASS)
931 
932 #define PACKET_TEST_ACTION(p, a) (p)->action &(a)
933 
934 static inline void PacketDrop(Packet *p, enum PacketDropReason r)
935 {
937  p->drop_reason = (uint8_t)r;
938 
940 }
941 
942 static inline void PacketPass(Packet *p)
943 {
945 }
946 
947 static inline uint8_t PacketTestAction(const Packet *p, const uint8_t a)
948 {
949  if (likely(p->root == NULL)) {
950  return PACKET_TEST_ACTION(p, a);
951  } else {
952  return PACKET_TEST_ACTION(p->root, a);
953  }
954 }
955 
956 #define PACKET_UPDATE_ACTION(p, a) (p)->action |= (a)
957 static inline void PacketUpdateAction(Packet *p, const uint8_t a)
958 {
959  if (likely(p->root == NULL)) {
960  PACKET_UPDATE_ACTION(p, a);
961  } else {
962  PACKET_UPDATE_ACTION(p->root, a);
963  }
964 }
965 
966 #define TUNNEL_INCR_PKT_RTV_NOLOCK(p) do { \
967  ((p)->root ? (p)->root->tunnel_rtv_cnt++ : (p)->tunnel_rtv_cnt++); \
968  } while (0)
969 
970 #define TUNNEL_INCR_PKT_TPR(p) do { \
971  SCMutexLock((p)->root ? &(p)->root->tunnel_mutex : &(p)->tunnel_mutex); \
972  ((p)->root ? (p)->root->tunnel_tpr_cnt++ : (p)->tunnel_tpr_cnt++); \
973  SCMutexUnlock((p)->root ? &(p)->root->tunnel_mutex : &(p)->tunnel_mutex); \
974  } while (0)
975 
976 #define TUNNEL_PKT_RTV(p) ((p)->root ? (p)->root->tunnel_rtv_cnt : (p)->tunnel_rtv_cnt)
977 #define TUNNEL_PKT_TPR(p) ((p)->root ? (p)->root->tunnel_tpr_cnt : (p)->tunnel_tpr_cnt)
978 
979 #define IS_TUNNEL_PKT(p) (((p)->flags & PKT_TUNNEL))
980 #define SET_TUNNEL_PKT(p) ((p)->flags |= PKT_TUNNEL)
981 #define UNSET_TUNNEL_PKT(p) ((p)->flags &= ~PKT_TUNNEL)
982 #define IS_TUNNEL_ROOT_PKT(p) (IS_TUNNEL_PKT(p) && (p)->root == NULL)
983 
984 #define IS_TUNNEL_PKT_VERDICTED(p) (((p)->flags & PKT_TUNNEL_VERDICTED))
985 #define SET_TUNNEL_PKT_VERDICTED(p) ((p)->flags |= PKT_TUNNEL_VERDICTED)
986 
994  DECODE_TUNNEL_IPV6_TEREDO, /**< separate protocol for stricter error handling */
998 };
999 
1001  const uint8_t *pkt, uint32_t len, enum DecodeTunnelProto proto);
1002 Packet *PacketDefragPktSetup(Packet *parent, const uint8_t *pkt, uint32_t len, uint8_t proto);
1003 void PacketDefragPktSetupParent(Packet *parent);
1006 Packet *PacketGetFromAlloc(void);
1009  DecodeThreadVars *dtv, Packet *p);
1010 void PacketFree(Packet *p);
1011 void PacketFreeOrRelease(Packet *p);
1012 int PacketCallocExtPkt(Packet *p, int datalen);
1013 int PacketCopyData(Packet *p, const uint8_t *pktdata, uint32_t pktlen);
1014 int PacketSetData(Packet *p, const uint8_t *pktdata, uint32_t pktlen);
1015 int PacketCopyDataOffset(Packet *p, uint32_t offset, const uint8_t *data, uint32_t datalen);
1016 const char *PktSrcToString(enum PktSrcEnum pkt_src);
1017 void PacketBypassCallback(Packet *p);
1018 void PacketSwap(Packet *p);
1019 
1023  const DecodeThreadVars *dtv, const Packet *p);
1024 const char *PacketDropReasonToString(enum PacketDropReason r);
1025 
1026 /* decoder functions */
1027 int DecodeEthernet(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1028 int DecodeSll(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1029 int DecodePPP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1030 int DecodePPPOESession(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1031 int DecodePPPOEDiscovery(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1032 int DecodeNull(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1033 int DecodeRaw(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1034 int DecodeIPV4(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t);
1035 int DecodeIPV6(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t);
1036 int DecodeICMPV4(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1037 int DecodeICMPV6(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1038 int DecodeTCP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t);
1039 int DecodeUDP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t);
1040 int DecodeSCTP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t);
1041 int DecodeESP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t);
1042 int DecodeGRE(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1043 int DecodeVLAN(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1044 int DecodeVNTag(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1045 int DecodeIEEE8021ah(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1046 int DecodeGeneve(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1047 int DecodeVXLAN(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1048 int DecodeMPLS(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1049 int DecodeERSPAN(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1050 int DecodeERSPANTypeI(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1051 int DecodeCHDLC(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1052 int DecodeTEMPLATE(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1053 int DecodeNSH(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
1054 
1055 #ifdef UNITTESTS
1056 void DecodeIPV6FragHeader(Packet *p, const uint8_t *pkt,
1057  uint16_t hdrextlen, uint16_t plen,
1058  uint16_t prev_hdrextlen);
1059 #endif
1060 
1061 void AddressDebugPrint(Address *);
1062 
1064  const uint8_t *pkt, uint32_t len);
1065 void DecodeGlobalConfig(void);
1066 void PacketAlertGetMaxConfig(void);
1067 void DecodeUnregisterCounters(void);
1068 
1069 #define ENGINE_SET_EVENT(p, e) do { \
1070  SCLogDebug("p %p event %d", (p), e); \
1071  if ((p)->events.cnt < PACKET_ENGINE_EVENT_MAX) { \
1072  (p)->events.events[(p)->events.cnt] = e; \
1073  (p)->events.cnt++; \
1074  } \
1075 } while(0)
1076 
1077 #define ENGINE_SET_INVALID_EVENT(p, e) do { \
1078  p->flags |= PKT_IS_INVALID; \
1079  ENGINE_SET_EVENT(p, e); \
1080 } while(0)
1081 
1082 
1083 
1084 #define ENGINE_ISSET_EVENT(p, e) ({ \
1085  int r = 0; \
1086  uint8_t u; \
1087  for (u = 0; u < (p)->events.cnt; u++) { \
1088  if ((p)->events.events[u] == (e)) { \
1089  r = 1; \
1090  break; \
1091  } \
1092  } \
1093  r; \
1094 })
1095 
1096 #ifndef IPPROTO_IPIP
1097 #define IPPROTO_IPIP 4
1098 #endif
1099 
1100 /* older libcs don't contain a def for IPPROTO_DCCP
1101  * inside of <netinet/in.h>
1102  * if it isn't defined let's define it here.
1103  */
1104 #ifndef IPPROTO_DCCP
1105 #define IPPROTO_DCCP 33
1106 #endif
1107 
1108 /* older libcs don't contain a def for IPPROTO_SCTP
1109  * inside of <netinet/in.h>
1110  * if it isn't defined let's define it here.
1111  */
1112 #ifndef IPPROTO_SCTP
1113 #define IPPROTO_SCTP 132
1114 #endif
1115 
1116 #ifndef IPPROTO_MH
1117 #define IPPROTO_MH 135
1118 #endif
1119 
1120 /* Host Identity Protocol (rfc 5201) */
1121 #ifndef IPPROTO_HIP
1122 #define IPPROTO_HIP 139
1123 #endif
1124 
1125 #ifndef IPPROTO_SHIM6
1126 #define IPPROTO_SHIM6 140
1127 #endif
1128 
1129 /* pcap provides this, but we don't want to depend on libpcap */
1130 #ifndef DLT_EN10MB
1131 #define DLT_EN10MB 1
1132 #endif
1133 
1134 #ifndef DLT_C_HDLC
1135 #define DLT_C_HDLC 104
1136 #endif
1137 
1138 /* taken from pcap's bpf.h */
1139 #ifndef DLT_RAW
1140 #ifdef __OpenBSD__
1141 #define DLT_RAW 14 /* raw IP */
1142 #else
1143 #define DLT_RAW 12 /* raw IP */
1144 #endif
1145 #endif
1146 
1147 #ifndef DLT_NULL
1148 #define DLT_NULL 0
1149 #endif
1150 
1151 /** libpcap shows us the way to linktype codes
1152  * \todo we need more & maybe put them in a separate file? */
1153 #define LINKTYPE_NULL DLT_NULL
1154 #define LINKTYPE_ETHERNET DLT_EN10MB
1155 #define LINKTYPE_LINUX_SLL 113
1156 #define LINKTYPE_PPP 9
1157 #define LINKTYPE_RAW DLT_RAW
1158 /* http://www.tcpdump.org/linktypes.html defines DLT_RAW as 101, yet others don't.
1159  * Libpcap on at least OpenBSD returns 101 as datalink type for RAW pcaps though. */
1160 #define LINKTYPE_RAW2 101
1161 #define LINKTYPE_IPV4 228
1162 #define LINKTYPE_GRE_OVER_IP 778
1163 #define LINKTYPE_CISCO_HDLC DLT_C_HDLC
1164 #define PPP_OVER_GRE 11
1165 #define VLAN_OVER_GRE 13
1167 /* Packet Flags */
1168 
1169 /** Flag to indicate that packet header or contents should not be inspected */
1170 #define PKT_NOPACKET_INSPECTION BIT_U32(0)
1171 // vacancy
1172 
1173 /** Flag to indicate that packet contents should not be inspected */
1174 #define PKT_NOPAYLOAD_INSPECTION BIT_U32(2)
1175 /** Packet was alloc'd this run, needs to be freed */
1176 #define PKT_ALLOC BIT_U32(3)
1177 /** Packet has matched a tag */
1178 #define PKT_HAS_TAG BIT_U32(4)
1179 /** Packet payload was added to reassembled stream */
1180 #define PKT_STREAM_ADD BIT_U32(5)
1181 /** Packet is part of established stream */
1182 #define PKT_STREAM_EST BIT_U32(6)
1183 /** Stream is in eof state */
1184 #define PKT_STREAM_EOF BIT_U32(7)
1185 #define PKT_HAS_FLOW BIT_U32(8)
1186 /** Pseudo packet to end the stream */
1187 #define PKT_PSEUDO_STREAM_END BIT_U32(9)
1188 /** Packet is modified by the stream engine, we need to recalc the csum and \
1189  reinject/replace */
1190 #define PKT_STREAM_MODIFIED BIT_U32(10)
1191 /** Packet mark is modified */
1192 #define PKT_MARK_MODIFIED BIT_U32(11)
1193 /** Exclude packet from pcap logging as it's part of a stream that has reassembly \
1194  depth reached. */
1195 #define PKT_STREAM_NOPCAPLOG BIT_U32(12)
1197 #define PKT_TUNNEL BIT_U32(13)
1198 #define PKT_TUNNEL_VERDICTED BIT_U32(14)
1200 /** Packet checksum is not computed (TX packet for example) */
1201 #define PKT_IGNORE_CHECKSUM BIT_U32(15)
1202 /** Packet comes from zero copy (ext_pkt must not be freed) */
1203 #define PKT_ZERO_COPY BIT_U32(16)
1205 #define PKT_HOST_SRC_LOOKED_UP BIT_U32(17)
1206 #define PKT_HOST_DST_LOOKED_UP BIT_U32(18)
1208 /** Packet is a fragment */
1209 #define PKT_IS_FRAGMENT BIT_U32(19)
1210 #define PKT_IS_INVALID BIT_U32(20)
1211 #define PKT_PROFILE BIT_U32(21)
1213 /** indication by decoder that it feels the packet should be handled by
1214  * flow engine: Packet::flow_hash will be set */
1215 #define PKT_WANTS_FLOW BIT_U32(22)
1217 /** protocol detection done */
1218 #define PKT_PROTO_DETECT_TS_DONE BIT_U32(23)
1219 #define PKT_PROTO_DETECT_TC_DONE BIT_U32(24)
1221 #define PKT_REBUILT_FRAGMENT \
1222  BIT_U32(25) /**< Packet is rebuilt from \
1223  * fragments. */
1224 #define PKT_DETECT_HAS_STREAMDATA \
1225  BIT_U32(26) /**< Set by Detect() if raw stream data is available. */
1227 #define PKT_PSEUDO_DETECTLOG_FLUSH BIT_U32(27) /**< Detect/log flush for protocol upgrade */
1229 /** Packet is part of stream in known bad condition (loss, wrong thread),
1230  * so flag it for not setting stream events */
1231 #define PKT_STREAM_NO_EVENTS BIT_U32(28)
1233 /** We had no alert on flow before this packet */
1234 #define PKT_FIRST_ALERTS BIT_U32(29)
1235 #define PKT_FIRST_TAG BIT_U32(30)
1237 /** \brief return 1 if the packet is a pseudo packet */
1238 #define PKT_IS_PSEUDOPKT(p) \
1239  ((p)->flags & (PKT_PSEUDO_STREAM_END|PKT_PSEUDO_DETECTLOG_FLUSH))
1240 
1241 #define PKT_SET_SRC(p, src_val) ((p)->pkt_src = src_val)
1243 #define PKT_DEFAULT_MAX_DECODED_LAYERS 16
1244 extern uint8_t decoder_max_layers;
1245 
1246 static inline bool PacketIncreaseCheckLayers(Packet *p)
1247 {
1248  p->nb_decoded_layers++;
1251  return false;
1252  }
1253  return true;
1254 }
1255 
1256 /** \brief Set the No payload inspection Flag for the packet.
1257  *
1258  * \param p Packet to set the flag in
1259  */
1260 static inline void DecodeSetNoPayloadInspectionFlag(Packet *p)
1261 {
1263 }
1264 
1265 /** \brief Set the No packet inspection Flag for the packet.
1266  *
1267  * \param p Packet to set the flag in
1268  */
1269 static inline void DecodeSetNoPacketInspectionFlag(Packet *p)
1270 {
1272 }
1273 
1274 /** \brief return true if *this* packet needs to trigger a verdict.
1275  *
1276  * If we have the root packet, and we have none outstanding,
1277  * we can verdict now.
1278  *
1279  * If we have a upper layer packet, it's the only one and root
1280  * is already processed, we can verdict now.
1281  *
1282  * Otherwise, a future packet will issue the verdict.
1283  */
1284 static inline bool VerdictTunnelPacket(Packet *p)
1285 {
1286  bool verdict = true;
1287  SCMutex *m = p->root ? &p->root->tunnel_mutex : &p->tunnel_mutex;
1288  SCMutexLock(m);
1289  const uint16_t outstanding = TUNNEL_PKT_TPR(p) - TUNNEL_PKT_RTV(p);
1290  SCLogDebug("tunnel: outstanding %u", outstanding);
1291 
1292  /* if there are packets outstanding, we won't verdict this one */
1293  if (IS_TUNNEL_ROOT_PKT(p) && !IS_TUNNEL_PKT_VERDICTED(p) && !outstanding) {
1294  // verdict
1295  SCLogDebug("root %p: verdict", p);
1296  } else if (!IS_TUNNEL_ROOT_PKT(p) && outstanding == 1 && p->root && IS_TUNNEL_PKT_VERDICTED(p->root)) {
1297  // verdict
1298  SCLogDebug("tunnel %p: verdict", p);
1299  } else {
1300  verdict = false;
1301  }
1302  SCMutexUnlock(m);
1303  return verdict;
1304 }
1305 
1306 static inline void DecodeLinkLayer(ThreadVars *tv, DecodeThreadVars *dtv,
1307  const int datalink, Packet *p, const uint8_t *data, const uint32_t len)
1308 {
1309  /* call the decoder */
1310  switch (datalink) {
1311  case LINKTYPE_ETHERNET:
1312  DecodeEthernet(tv, dtv, p, data, len);
1313  break;
1314  case LINKTYPE_LINUX_SLL:
1315  DecodeSll(tv, dtv, p, data, len);
1316  break;
1317  case LINKTYPE_PPP:
1318  DecodePPP(tv, dtv, p, data, len);
1319  break;
1320  case LINKTYPE_RAW:
1321  case LINKTYPE_GRE_OVER_IP:
1322  DecodeRaw(tv, dtv, p, data, len);
1323  break;
1324  case LINKTYPE_NULL:
1325  DecodeNull(tv, dtv, p, data, len);
1326  break;
1327  case LINKTYPE_CISCO_HDLC:
1328  DecodeCHDLC(tv, dtv, p, data, len);
1329  break;
1330  default:
1331  SCLogError(SC_ERR_DATALINK_UNIMPLEMENTED, "datalink type "
1332  "%"PRId32" not yet supported", datalink);
1333  break;
1334  }
1335 }
1336 
1337 /** \brief decode network layer
1338  * \retval bool true if successful, false if unknown */
1339 static inline bool DecodeNetworkLayer(ThreadVars *tv, DecodeThreadVars *dtv,
1340  const uint16_t proto, Packet *p, const uint8_t *data, const uint32_t len)
1341 {
1342  switch (proto) {
1343  case ETHERNET_TYPE_IP: {
1344  uint16_t ip_len = (len < USHRT_MAX) ? (uint16_t)len : (uint16_t)USHRT_MAX;
1345  DecodeIPV4(tv, dtv, p, data, ip_len);
1346  break;
1347  }
1348  case ETHERNET_TYPE_IPV6: {
1349  uint16_t ip_len = (len < USHRT_MAX) ? (uint16_t)len : (uint16_t)USHRT_MAX;
1350  DecodeIPV6(tv, dtv, p, data, ip_len);
1351  break;
1352  }
1354  DecodePPPOESession(tv, dtv, p, data, len);
1355  break;
1357  DecodePPPOEDiscovery(tv, dtv, p, data, len);
1358  break;
1359  case ETHERNET_TYPE_VLAN:
1360  case ETHERNET_TYPE_8021AD:
1362  if (p->vlan_idx >= 2) {
1364  } else {
1365  DecodeVLAN(tv, dtv, p, data, len);
1366  }
1367  break;
1368  case ETHERNET_TYPE_8021AH:
1369  DecodeIEEE8021ah(tv, dtv, p, data, len);
1370  break;
1371  case ETHERNET_TYPE_ARP:
1372  break;
1375  DecodeMPLS(tv, dtv, p, data, len);
1376  break;
1377  case ETHERNET_TYPE_DCE:
1380  } else {
1381  DecodeEthernet(tv, dtv, p, data, len);
1382  }
1383  break;
1384  case ETHERNET_TYPE_VNTAG:
1385  DecodeVNTag(tv, dtv, p, data, len);
1386  break;
1387  case ETHERNET_TYPE_NSH:
1388  DecodeNSH(tv, dtv, p, data, len);
1389  break;
1390  default:
1391  SCLogDebug("unknown ether type: %" PRIx16 "", proto);
1392  return false;
1393  }
1394  return true;
1395 }
1396 
1397 #endif /* __DECODE_H__ */
CaptureStats
struct CaptureStats_ CaptureStats
suricata-plugin.h
ENGINE_SET_EVENT
#define ENGINE_SET_EVENT(p, e)
Definition: decode.h:1069
DecodeThreadVars_::counter_flow_get_used_eval_busy
uint16_t counter_flow_get_used_eval_busy
Definition: decode.h:738
PKT_DROP_REASON_DEFRAG_MEMCAP
@ PKT_DROP_REASON_DEFRAG_MEMCAP
Definition: decode.h:411
Packet_::greh
GREHdr * greh
Definition: decode.h:578
PKT_DROP_REASON_DEFRAG_ERROR
@ PKT_DROP_REASON_DEFRAG_ERROR
Definition: decode.h:410
decode-ethernet.h
decode-raw.h
decode-tcp.h
DecodeThreadVars_::counter_defrag_ipv4_reassembled
uint16_t counter_defrag_ipv4_reassembled
Definition: decode.h:718
Packet_::proto
uint8_t proto
Definition: decode.h:464
spin_lock_cnt
thread_local uint64_t spin_lock_cnt
PKT_DROP_REASON_RULES_THRESHOLD
@ PKT_DROP_REASON_RULES_THRESHOLD
Definition: decode.h:419
DecodeIPV6
int DecodeIPV6(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t)
Definition: decode-ipv6.c:572
DecodeERSPAN
int DecodeERSPAN(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
ERSPAN Type II.
Definition: decode-erspan.c:76
DecodeGeneve
int DecodeGeneve(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Definition: decode-geneve.c:185
source-nflog.h
decode-mpls.h
DecodeThreadVars_::counter_flow_udp
uint16_t counter_flow_udp
Definition: decode.h:731
len
uint8_t len
Definition: app-layer-dnp3.h:2
DecodeThreadVars_::counter_bytes
uint16_t counter_bytes
Definition: decode.h:678
Packet_::icmp_s
struct Packet_::@33::@42 icmp_s
DECODE_TUNNEL_IPV6
@ DECODE_TUNNEL_IPV6
Definition: decode.h:993
source-pcap.h
CaptureStats_::counter_ips_blocked
uint16_t counter_ips_blocked
Definition: decode.h:757
PktProfilingData_::ticks_end
uint64_t ticks_end
Definition: decode.h:364
decode-erspan.h
decode-vxlan.h
PACKET_SET_ACTION
#define PACKET_SET_ACTION(p, a)
Definition: decode.h:909
PacketAlert_::s
const struct Signature_ * s
Definition: decode.h:284
DecodeThreadVars_::counter_eth
uint16_t counter_eth
Definition: decode.h:686
IPV4Vars_
Definition: decode-ipv4.h:172
DecodeThreadVars_::counter_flow_active
uint16_t counter_flow_active
Definition: decode.h:729
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
Packet_::sctph
SCTPHdr * sctph
Definition: decode.h:566
NapatechPacketVars_
Definition: util-napatech.h:30
Packet_::code
uint8_t code
Definition: decode.h:453
PacketFreeOrRelease
void PacketFreeOrRelease(Packet *p)
Return a packet to where it was allocated.
Definition: decode.c:194
PLUGIN_VAR_SIZE
#define PLUGIN_VAR_SIZE
Definition: suricata-plugin.h:30
DecodeThreadVars_::counter_flow_icmp4
uint16_t counter_flow_icmp4
Definition: decode.h:732
VLAN_HEADER_TOO_MANY_LAYERS
@ VLAN_HEADER_TOO_MANY_LAYERS
Definition: decode-events.h:146
DecodeThreadVars_::counter_vxlan
uint16_t counter_vxlan
Definition: decode.h:705
DecodeThreadVars_::counter_max_pkt_size
uint16_t counter_max_pkt_size
Definition: decode.h:680
PacketCopyData
int PacketCopyData(Packet *p, const uint8_t *pktdata, uint32_t pktlen)
Copy data to Packet payload and set packet length.
Definition: decode.c:295
decode-pppoe.h
Packet_::vlan_id
uint16_t vlan_id[2]
Definition: decode.h:469
PacketBypassCallback
void PacketBypassCallback(Packet *p)
Definition: decode.c:441
DecodeSCTP
int DecodeSCTP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t)
Definition: decode-sctp.c:66
ICMPV4Vars_
Definition: decode-icmpv4.h:185
DecodeThreadVars_::counter_avg_pkt_size
uint16_t counter_avg_pkt_size
Definition: decode.h:679
PktProfiling_
Per pkt stats storage.
Definition: decode.h:393
Address_::address_un_data16
uint16_t address_un_data16[8]
Definition: decode.h:126
PktProfilingPrefilterData_::engines
PktProfilingPrefilterEngine * engines
Definition: decode.h:388
DecodePPP
int DecodePPP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Definition: decode-ppp.c:44
Address_::address_un_in6
struct in6_addr address_un_in6
Definition: decode.h:128
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
PKT_DROP_REASON_STREAM_MEMCAP
@ PKT_DROP_REASON_STREAM_MEMCAP
Definition: decode.h:415
PktProfilingTmmData_
Per TMM stats storage.
Definition: decode.h:343
IPV6ExtHdrs_
Definition: decode-ipv6.h:215
ACTION_PASS
#define ACTION_PASS
Definition: action-globals.h:34
PktPool_
Definition: tmqh-packetpool.h:40
Packet_::host_src
struct Host_ * host_src
Definition: decode.h:599
PKT_DROP_REASON_FLOW_MEMCAP
@ PKT_DROP_REASON_FLOW_MEMCAP
Definition: decode.h:412
PPPOESessionHdr_
Definition: decode-pppoe.h:39
PacketDropReasonToString
const char * PacketDropReasonToString(enum PacketDropReason r)
Definition: decode.c:780
PacketEngineEvents_::events
uint8_t events[PACKET_ENGINE_EVENT_MAX]
Definition: decode.h:326
CaptureStats_
Definition: decode.h:754
DECODE_TUNNEL_IPV6_TEREDO
@ DECODE_TUNNEL_IPV6_TEREDO
Definition: decode.h:994
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
DecodeEthernet
int DecodeEthernet(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Definition: decode-ethernet.c:42
rwr_lock_cnt
thread_local uint64_t rwr_lock_cnt
Packet_::pcap_cnt
uint64_t pcap_cnt
Definition: decode.h:603
PktProfiling_::ticks_end
uint64_t ticks_end
Definition: decode.h:395
TCPVars_
Definition: decode-tcp.h:155
AddressDebugPrint
void AddressDebugPrint(Address *)
Debug print function for printing addresses.
Definition: decode.c:667
PKT_SRC_DECODER_IPV4
@ PKT_SRC_DECODER_IPV4
Definition: decode.h:53
DecodeThreadVars_::counter_flow_spare_sync_avg
uint16_t counter_flow_spare_sync_avg
Definition: decode.h:744
PacketDefragPktSetup
Packet * PacketDefragPktSetup(Packet *parent, const uint8_t *pkt, uint32_t len, uint8_t proto)
Setup a pseudo packet (reassembled frags)
Definition: decode.c:385
PacketQueue_
simple fifo queue for packets with mutex and cond Calling the mutex or triggering the cond is respons...
Definition: packet-queue.h:47
Packet_::payload
uint8_t * payload
Definition: decode.h:582
PacketAlerts_::cnt
uint16_t cnt
Definition: decode.h:306
ETHERNET_TYPE_IPV6
#define ETHERNET_TYPE_IPV6
Definition: decode-ethernet.h:39
PKT_SRC_CAPTURE_TIMEOUT
@ PKT_SRC_CAPTURE_TIMEOUT
Definition: decode.h:61
DecodeUDP
int DecodeUDP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t)
Definition: decode-udp.c:75
action-globals.h
Packet_::flags
uint32_t flags
Definition: decode.h:477
decode-udp.h
Packet_::action
uint8_t action
Definition: decode.h:586
PacketAlertCreate
PacketAlert * PacketAlertCreate(void)
Initialize PacketAlerts with dynamic alerts array size.
Definition: decode.c:83
PktProfilingDetectData
struct PktProfilingDetectData_ PktProfilingDetectData
decode-null.h
DecodeThreadVars_::counter_vntag
uint16_t counter_vntag
Definition: decode.h:706
Packet_::vlan_idx
uint8_t vlan_idx
Definition: decode.h:470
Flow_
Flow data structure.
Definition: flow.h:356
DecodeThreadVars_::counter_flow_get_used_eval
uint16_t counter_flow_get_used_eval
Definition: decode.h:736
LiveDevice_
Definition: util-device.h:40
PROF_DETECT_SIZE
@ PROF_DETECT_SIZE
Definition: suricata-common.h:433
Packet_::l4vars
union Packet_::@41 l4vars
PktVar_::next
struct PktVar_ * next
Definition: decode.h:331
DecoderFunc
int(* DecoderFunc)(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Definition: decode.h:1063
PktProfilingTmmData_::ticks_end
uint64_t ticks_end
Definition: decode.h:345
Packet_::ipfw_v
IPFWPacketVars ipfw_v
Definition: decode.h:496
Packet_::pool
struct PktPool_ * pool
Definition: decode.h:649
Packet_::ip4vars
IPV4Vars ip4vars
Definition: decode.h:546
IS_TUNNEL_ROOT_PKT
#define IS_TUNNEL_ROOT_PKT(p)
Definition: decode.h:982
CHECKSUM_VALIDATION_RXONLY
@ CHECKSUM_VALIDATION_RXONLY
Definition: decode.h:46
Packet_::ip6vars
IPV6Vars ip6vars
Definition: decode.h:548
DECODE_TUNNEL_ERSPANI
@ DECODE_TUNNEL_ERSPANI
Definition: decode.h:990
PacketAlerts_::alerts
PacketAlert * alerts
Definition: decode.h:309
LINKTYPE_LINUX_SLL
#define LINKTYPE_LINUX_SLL
Definition: decode.h:1155
PktProfilingTmmData
struct PktProfilingTmmData_ PktProfilingTmmData
Per TMM stats storage.
DecodeThreadVars_::counter_teredo
uint16_t counter_teredo
Definition: decode.h:709
DecodeThreadVars_::counter_erspan
uint16_t counter_erspan
Definition: decode.h:713
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:253
DecodeVXLAN
int DecodeVXLAN(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Definition: decode-vxlan.c:126
AppLayerDecoderEventsResetEvents
void AppLayerDecoderEventsResetEvents(AppLayerDecoderEvents *events)
Definition: app-layer-events.c:123
Packet_::pppoesh
PPPOESessionHdr * pppoesh
Definition: decode.h:575
DecodeThreadVars_::counter_raw
uint16_t counter_raw
Definition: decode.h:696
SCMutexLock
#define SCMutexLock(mut)
Definition: threads-debug.h:117
DecodeThreadVars
struct DecodeThreadVars_ DecodeThreadVars
Structure to hold thread specific data for all decode modules.
PktProfilingPrefilterData_
Definition: decode.h:387
PacketAlerts_::drop
PacketAlert drop
Definition: decode.h:312
DecodeVNTag
int DecodeVNTag(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Definition: decode-vntag.c:58
Address_
Definition: decode.h:122
Address_::address
union Address_::@32 address
CHECKSUM_VALIDATION_DISABLE
@ CHECKSUM_VALIDATION_DISABLE
Definition: decode.h:43
DecodeThreadVars_::counter_flow_tcp
uint16_t counter_flow_tcp
Definition: decode.h:730
CHECKSUM_VALIDATION_KERNEL
@ CHECKSUM_VALIDATION_KERNEL
Definition: decode.h:47
PacketDecodeFinalize
void PacketDecodeFinalize(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
Finalize decoding of a packet.
Definition: decode.c:147
Address_::address_un_data32
uint32_t address_un_data32[4]
Definition: decode.h:125
Packet_::tcpvars
TCPVars tcpvars
Definition: decode.h:554
proto
uint8_t proto
Definition: decode-template.h:0
m
SCMutex m
Definition: flow-hash.h:6
PKT_NOPAYLOAD_INSPECTION
#define PKT_NOPAYLOAD_INSPECTION
Definition: decode.h:1174
PacketAlertGetMaxConfig
void PacketAlertGetMaxConfig(void)
Definition: decode.c:850
DecodeICMPV6
int DecodeICMPV6(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Decode ICMPV6 packets and fill the Packet with the decoded info.
Definition: decode-icmpv6.c:189
PktProfilingDetectData_::ticks_end
uint64_t ticks_end
Definition: decode.h:369
decoder_max_layers
uint8_t decoder_max_layers
Definition: decode.c:76
DecodeThreadVars_::counter_tcp_active_sessions
uint16_t counter_tcp_active_sessions
Definition: decode.h:727
PacketAlert
struct PacketAlert_ PacketAlert
Packet_::host_dst
struct Host_ * host_dst
Definition: decode.h:600
PktProfilingLoggerData
struct PktProfilingLoggerData_ PktProfilingLoggerData
Packet_::flowflags
uint8_t flowflags
Definition: decode.h:473
PktProfilingPrefilterEngine
struct PktProfilingPrefilterEngine_ PktProfilingPrefilterEngine
Packet_::BypassPacketsFlow
int(* BypassPacketsFlow)(struct Packet_ *)
Definition: decode.h:527
ALPROTO_MAX
@ ALPROTO_MAX
Definition: app-layer-protos.h:75
PacketDropReason
PacketDropReason
Definition: decode.h:407
DecodeThreadVars_::counter_max_mac_addrs_src
uint16_t counter_max_mac_addrs_src
Definition: decode.h:681
PktProfiling_::app
PktProfilingAppData app[ALPROTO_MAX]
Definition: decode.h:399
PktProfiling_::ticks_start
uint64_t ticks_start
Definition: decode.h:394
DecodeUnregisterCounters
void DecodeUnregisterCounters(void)
Definition: decode.c:513
rww_lock_contention
thread_local uint64_t rww_lock_contention
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:583
DecodeThreadVars_::counter_flow_get_used
uint16_t counter_flow_get_used
Definition: decode.h:735
Packet_::alerts
PacketAlerts alerts
Definition: decode.h:597
Packet_::tunnel_tpr_cnt
uint16_t tunnel_tpr_cnt
Definition: decode.h:641
AppLayerDecoderEvents_
Data structure to store app layer decoder events.
Definition: app-layer-events.h:34
Packet_::app_layer_events
AppLayerDecoderEvents * app_layer_events
Definition: decode.h:609
Packet_::events
PacketEngineEvents events
Definition: decode.h:607
PacketAlertFree
void PacketAlertFree(PacketAlert *pa)
Definition: decode.c:91
ETHERNET_TYPE_8021QINQ
#define ETHERNET_TYPE_8021QINQ
Definition: decode-ethernet.h:47
DecodeThreadVars_::counter_flow_spare_sync_empty
uint16_t counter_flow_spare_sync_empty
Definition: decode.h:742
PktProfilingAppData_::ticks_spent
uint64_t ticks_spent
Definition: decode.h:374
DecodeThreadVars_::counter_flow_tcp_reuse
uint16_t counter_flow_tcp_reuse
Definition: decode.h:734
DecodeRaw
int DecodeRaw(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Definition: decode-raw.c:47
PacketAlert_::tx_id
uint64_t tx_id
Definition: decode.h:285
rwr_lock_contention
thread_local uint64_t rwr_lock_contention
LINKTYPE_NULL
#define LINKTYPE_NULL
Definition: decode.h:1153
DECODE_TUNNEL_NSH
@ DECODE_TUNNEL_NSH
Definition: decode.h:996
DecodeThreadVars_::counter_flow_total
uint16_t counter_flow_total
Definition: decode.h:728
PacketAlert_::action
uint8_t action
Definition: decode.h:282
detect-reference.h
Packet_::datalink
int datalink
Definition: decode.h:616
Packet_::profile
PktProfiling * profile
Definition: decode.h:652
spin_lock_wait_ticks
thread_local uint64_t spin_lock_wait_ticks
CHECKSUM_VALIDATION_ENABLE
@ CHECKSUM_VALIDATION_ENABLE
Definition: decode.h:44
decode-gre.h
DecodeRegisterPerfCounters
void DecodeRegisterPerfCounters(DecodeThreadVars *, ThreadVars *)
Definition: decode.c:523
Packet_::level3_comp_csum
int32_t level3_comp_csum
Definition: decode.h:536
DecodeThreadVars_::counter_flow_spare_sync
uint16_t counter_flow_spare_sync
Definition: decode.h:741
DECODE_TUNNEL_ERSPANII
@ DECODE_TUNNEL_ERSPANII
Definition: decode.h:989
CHECKSUM_VALIDATION_AUTO
@ CHECKSUM_VALIDATION_AUTO
Definition: decode.h:45
DecodeThreadVars_::counter_ipv6inipv6
uint16_t counter_ipv6inipv6
Definition: decode.h:712
Packet_::pktlen
uint32_t pktlen
Definition: decode.h:591
decode-ipv6.h
TUNNEL_PKT_TPR
#define TUNNEL_PKT_TPR(p)
Definition: decode.h:977
Packet_::level4_comp_csum
int32_t level4_comp_csum
Definition: decode.h:538
util-debug.h
DecodeThreadVars_::counter_flow_get_used_failed
uint16_t counter_flow_get_used_failed
Definition: decode.h:739
PKT_SRC_WIRE
@ PKT_SRC_WIRE
Definition: decode.h:51
source-nfq.h
Packet_::pktvar
PktVar * pktvar
Definition: decode.h:530
CaptureStats_::counter_ips_rejected
uint16_t counter_ips_rejected
Definition: decode.h:758
DPDKPacketVars_
per packet DPDK vars
Definition: source-dpdk.h:78
DecodeThreadVars_::counter_icmpv4
uint16_t counter_icmpv4
Definition: decode.h:692
DecodeThreadVars_::counter_ppp
uint16_t counter_ppp
Definition: decode.h:700
ETHERNET_TYPE_8021AD
#define ETHERNET_TYPE_8021AD
Definition: decode-ethernet.h:43
PacketAlert_::num
SigIntId num
Definition: decode.h:281
PKT_DROP_REASON_APPLAYER_ERROR
@ PKT_DROP_REASON_APPLAYER_ERROR
Definition: decode.h:416
SCMutexUnlock
#define SCMutexUnlock(mut)
Definition: threads-debug.h:119
PacketSwap
void PacketSwap(Packet *p)
switch direction of a packet
Definition: decode.c:488
DecodeMPLS
int DecodeMPLS(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Definition: decode-mpls.c:49
AppLayerThreadCtx_
This is for the app layer in general and it contains per thread context relevant to both the alpd and...
Definition: app-layer.c:56
PktSrcEnum
PktSrcEnum
Definition: decode.h:50
PKT_DROP_REASON_NOT_SET
@ PKT_DROP_REASON_NOT_SET
Definition: decode.h:408
flow-worker.h
PktVar_::value
uint8_t * value
Definition: decode.h:337
PktProfilingAppData
struct PktProfilingAppData_ PktProfilingAppData
DecodeTunnelProto
DecodeTunnelProto
Definition: decode.h:987
Packet_::prev
struct Packet_ * prev
Definition: decode.h:613
Packet
struct Packet_ Packet
decode-ppp.h
Packet_::pcap_v
PcapPacketVars pcap_v
Definition: decode.h:520
IS_TUNNEL_PKT_VERDICTED
#define IS_TUNNEL_PKT_VERDICTED(p)
Definition: decode.h:984
CaptureStatsSetup
void CaptureStatsSetup(ThreadVars *tv, CaptureStats *s)
Definition: decode.c:825
PKT_SRC_DECODER_TEREDO
@ PKT_SRC_DECODER_TEREDO
Definition: decode.h:55
DecodeTEMPLATE
int DecodeTEMPLATE(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Function to decode TEMPLATE packets.
Definition: decode-template.c:51
Packet_::tunnel_rtv_cnt
uint16_t tunnel_rtv_cnt
Definition: decode.h:639
DecodeVLAN
int DecodeVLAN(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Definition: decode-vlan.c:60
DecodeESP
int DecodeESP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t)
Function to decode IPSEC-ESP packets.
Definition: decode-esp.c:64
rww_lock_cnt
thread_local uint64_t rww_lock_cnt
Packet_::ethh
EthernetHdr * ethh
Definition: decode.h:533
DecodeNSH
int DecodeNSH(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Function to decode NSH packets.
Definition: decode-nsh.c:46
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
mutex_lock_contention
thread_local uint64_t mutex_lock_contention
spin_lock_contention
thread_local uint64_t spin_lock_contention
PktProfilingData_
Definition: decode.h:362
DECODE_TUNNEL_PPP
@ DECODE_TUNNEL_PPP
Definition: decode.h:995
Packet_::sp
Port sp
Definition: decode.h:449
PktProfiling_::logger
PktProfilingLoggerData logger[LOGGER_SIZE]
Definition: decode.h:401
PacketFree
void PacketFree(Packet *p)
Return a malloced packet.
Definition: decode.c:134
PktSrcToString
const char * PktSrcToString(enum PktSrcEnum pkt_src)
Definition: decode.c:736
PktVar
struct PktVar_ PktVar
DecodeThreadVars_::counter_vlan_qinq
uint16_t counter_vlan_qinq
Definition: decode.h:704
IPV6Vars_
get the highest proto/next header field we know
Definition: decode-ipv6.h:104
LINKTYPE_GRE_OVER_IP
#define LINKTYPE_GRE_OVER_IP
Definition: decode.h:1162
LINKTYPE_PPP
#define LINKTYPE_PPP
Definition: decode.h:1156
PktProfilingDetectData_
Definition: decode.h:367
PktVar_::key
uint8_t * key
Definition: decode.h:336
decode-icmpv6.h
PacketAlerts_::discarded
uint16_t discarded
Definition: decode.h:307
source-pfring.h
DecodeSll
int DecodeSll(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Definition: decode-sll.c:41
PKT_DROP_REASON_RULES
@ PKT_DROP_REASON_RULES
Definition: decode.h:418
DecodeThreadVars_::counter_defrag_ipv6_timeouts
uint16_t counter_defrag_ipv6_timeouts
Definition: decode.h:722
LOGGER_SIZE
@ LOGGER_SIZE
Definition: suricata-common.h:492
PacketCallocExtPkt
int PacketCallocExtPkt(Packet *p, int datalen)
Definition: decode.c:227
Address
struct Address_ Address
AppLayerDecoderEventsFreeEvents
void AppLayerDecoderEventsFreeEvents(AppLayerDecoderEvents **events)
Definition: app-layer-events.c:132
ETHERNET_TYPE_MPLS_UNICAST
#define ETHERNET_TYPE_MPLS_UNICAST
Definition: decode-mpls.h:29
PKT_SRC_STREAM_TCP_DETECTLOG_FLUSH
@ PKT_SRC_STREAM_TCP_DETECTLOG_FLUSH
Definition: decode.h:58
DECODE_TUNNEL_VLAN
@ DECODE_TUNNEL_VLAN
Definition: decode.h:991
Packet_::icmpv6h
ICMPV6Hdr * icmpv6h
Definition: decode.h:572
util-napatech.h
ETHERNET_TYPE_PPPOE_DISC
#define ETHERNET_TYPE_PPPOE_DISC
Definition: decode-ethernet.h:41
PKT_SRC_DECODER_IPV6
@ PKT_SRC_DECODER_IPV6
Definition: decode.h:54
CaptureStats_::counter_ips_accepted
uint16_t counter_ips_accepted
Definition: decode.h:756
IPV6Hdr_
Definition: decode-ipv6.h:32
Packet_
Definition: decode.h:442
DecodeThreadVars_::counter_nsh
uint16_t counter_nsh
Definition: decode.h:714
GENERIC_TOO_MANY_LAYERS
@ GENERIC_TOO_MANY_LAYERS
Definition: decode-events.h:220
DECODE_TUNNEL_IPV4
@ DECODE_TUNNEL_IPV4
Definition: decode.h:992
decode-sll.h
DecodeThreadVars_::app_tctx
AppLayerThreadCtx * app_tctx
Definition: decode.h:674
DecodeThreadVars_::counter_defrag_ipv4_timeouts
uint16_t counter_defrag_ipv4_timeouts
Definition: decode.h:719
decode-icmpv4.h
DecodeThreadVars_::counter_sll
uint16_t counter_sll
Definition: decode.h:695
source-ipfw.h
Address_::address_un_data8
uint8_t address_un_data8[16]
Definition: decode.h:127
TMM_SIZE
@ TMM_SIZE
Definition: tm-threads-common.h:77
PacketEngineEvents_
Definition: decode.h:324
source-netmap.h
Packet_::ip4h
IPV4Hdr * ip4h
Definition: decode.h:540
PKT_DROP_REASON_STREAM_ERROR
@ PKT_DROP_REASON_STREAM_ERROR
Definition: decode.h:414
Port
uint16_t Port
Definition: decode.h:246
DecodeThreadVars_::counter_sctp
uint16_t counter_sctp
Definition: decode.h:698
Packet_::livedev
struct LiveDevice_ * livedev
Definition: decode.h:595
source-windivert.h
DecodeThreadVars_::counter_invalid
uint16_t counter_invalid
Definition: decode.h:684
ETHERNET_TYPE_VNTAG
#define ETHERNET_TYPE_VNTAG
Definition: decode-ethernet.h:51
DecodeThreadVars_::counter_ieee8021ah
uint16_t counter_ieee8021ah
Definition: decode.h:707
decode-nsh.h
rww_lock_wait_ticks
thread_local uint64_t rww_lock_wait_ticks
DecodeTCP
int DecodeTCP(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t)
Definition: decode-tcp.c:251
DecodeThreadVars_::counter_ipv4inipv6
uint16_t counter_ipv4inipv6
Definition: decode.h:711
ETHERNET_TYPE_NSH
#define ETHERNET_TYPE_NSH
Definition: decode-ethernet.h:50
DecodeThreadVars_::counter_vlan
uint16_t counter_vlan
Definition: decode.h:703
DECODE_TUNNEL_ETHERNET
@ DECODE_TUNNEL_ETHERNET
Definition: decode.h:988
DecodeThreadVars_::counter_tcp
uint16_t counter_tcp
Definition: decode.h:690
ETHERNET_TYPE_DCE
#define ETHERNET_TYPE_DCE
Definition: decode-ethernet.h:49
DecodeThreadVars_::counter_pkts
uint16_t counter_pkts
Definition: decode.h:677
rwr_lock_wait_ticks
thread_local uint64_t rwr_lock_wait_ticks
decode-events.h
PktProfilingPrefilterEngine_
Definition: decode.h:383
PktProfilingData_::ticks_start
uint64_t ticks_start
Definition: decode.h:363
DecodeNull
int DecodeNull(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Definition: decode-null.c:56
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:30
DecodeIPV4
int DecodeIPV4(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint16_t)
Definition: decode-ipv4.c:517
PacketAlert_::frame_id
int64_t frame_id
Definition: decode.h:286
PktProfilingPrefilterData
struct PktProfilingPrefilterData_ PktProfilingPrefilterData
Packet_::ntpv
NapatechPacketVars ntpv
Definition: decode.h:655
decode-vlan.h
IPV4Hdr_
Definition: decode-ipv4.h:71
default_packet_size
uint32_t default_packet_size
Definition: decode.c:72
LINKTYPE_RAW
#define LINKTYPE_RAW
Definition: decode.h:1157
PACKET_UPDATE_ACTION
#define PACKET_UPDATE_ACTION(p, a)
Definition: decode.h:956
Packet_::nb_decoded_layers
uint8_t nb_decoded_layers
Definition: decode.h:621
PacketAlert_::flags
uint8_t flags
Definition: decode.h:283
PKT_SRC_DECODER_GENEVE
@ PKT_SRC_DECODER_GENEVE
Definition: decode.h:62
decode-ipv4.h
DecodeThreadVars_::counter_chdlc
uint16_t counter_chdlc
Definition: decode.h:687
Packet_::ppph
PPPHdr * ppph
Definition: decode.h:574
Packet_::nfq_v
NFQPacketVars nfq_v
Definition: decode.h:493
ICMPV6Hdr_
Definition: decode-icmpv6.h:145
PktProfiling_::detect
PktProfilingDetectData detect[PROF_DETECT_SIZE]
Definition: decode.h:400
Packet_::icmpv4vars
ICMPV4Vars icmpv4vars
Definition: decode.h:555
Packet_::ReleasePacket
void(* ReleasePacket)(struct Packet_ *)
Definition: decode.h:524
Packet_::tenant_id
uint32_t tenant_id
Definition: decode.h:644
Packet_::flow
struct Flow_ * flow
Definition: decode.h:479
DecodeGRE
int DecodeGRE(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Function to decode GRE packets.
Definition: decode-gre.c:47
ICMPV6Vars_
Definition: decode-icmpv6.h:162
PktProfiling
struct PktProfiling_ PktProfiling
Per pkt stats storage.
DecodeThreadVarsFree
void DecodeThreadVarsFree(ThreadVars *, DecodeThreadVars *)
Definition: decode.c:703
IPFWPacketVars_
Definition: source-ipfw.h:32
source-dpdk.h
PktProfilingLoggerData_::ticks_end
uint64_t ticks_end
Definition: decode.h:379
PktProfilingPrefilterEngine_::ticks_spent
uint64_t ticks_spent
Definition: decode.h:384
DecodeThreadVars_::counter_flow_spare_sync_incomplete
uint16_t counter_flow_spare_sync_incomplete
Definition: decode.h:743
Packet_::ts
struct timeval ts
Definition: decode.h:485
PKT_DROP_REASON_APPLAYER_MEMCAP
@ PKT_DROP_REASON_APPLAYER_MEMCAP
Definition: decode.h:417
DecodeGlobalConfig
void DecodeGlobalConfig(void)
Definition: decode.c:833
ChecksumValidationMode
ChecksumValidationMode
Definition: decode.h:42
suricata-common.h
PKT_SRC_FFR
@ PKT_SRC_FFR
Definition: decode.h:57
DecodeIPV6FragHeader
void DecodeIPV6FragHeader(Packet *p, const uint8_t *pkt, uint16_t hdrextlen, uint16_t plen, uint16_t prev_hdrextlen)
Definition: decode-ipv6.c:101
ETHERNET_TYPE_8021AH
#define ETHERNET_TYPE_8021AH
Definition: decode-ethernet.h:44
NFQPacketVars_
Definition: source-nfq.h:40
DecodeThreadVars_::counter_flow_icmp6
uint16_t counter_flow_icmp6
Definition: decode.h:733
Packet_::tcph
TCPHdr * tcph
Definition: decode.h:562
DecodeThreadVars_::counter_ipv6
uint16_t counter_ipv6
Definition: decode.h:689
PROFILE_FLOWWORKER_SIZE
@ PROFILE_FLOWWORKER_SIZE
Definition: flow-worker.h:29
CaptureStats_::counter_ips_replaced
uint16_t counter_ips_replaced
Definition: decode.h:759
ETHERNET_DCE_HEADER_LEN
#define ETHERNET_DCE_HEADER_LEN
Definition: decode-ethernet.h:30
DecodeThreadVars_::counter_gre
uint16_t counter_gre
Definition: decode.h:702
ACTION_DROP
#define ACTION_DROP
Definition: action-globals.h:30
DecodeThreadVars_::counter_esp
uint16_t counter_esp
Definition: decode.h:699
Packet_::ext_pkt
uint8_t * ext_pkt
Definition: decode.h:592
PacketAlerts
struct PacketAlerts_ PacketAlerts
DecodeICMPV4
int DecodeICMPV4(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Main ICMPv4 decoding function.
Definition: decode-icmpv4.c:156
decode-esp.h
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:257
DecodeThreadVars_::counter_defrag_ipv6_reassembled
uint16_t counter_defrag_ipv6_reassembled
Definition: decode.h:721
DecodeThreadVars_::counter_udp
uint16_t counter_udp
Definition: decode.h:691
PacketUpdateEngineEventCounters
void PacketUpdateEngineEventCounters(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
Definition: decode.c:154
decode-sctp.h
decode-geneve.h
CaptureStatsUpdate
void CaptureStatsUpdate(ThreadVars *tv, CaptureStats *s, const Packet *p)
Definition: decode.c:812
PKT_SRC_DEFRAG
@ PKT_SRC_DEFRAG
Definition: decode.h:56
Packet_::icmpv4h
ICMPV4Hdr * icmpv4h
Definition: decode.h:570
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:29
PfringPacketVars_
per packet Pfring vars
Definition: source-pfring.h:60
NetmapPacketVars_
Definition: source-netmap.h:71
DecodeThreadVars_::counter_ipv4
uint16_t counter_ipv4
Definition: decode.h:688
threadvars.h
PacketGetFromAlloc
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
Definition: decode.c:173
TUNNEL_PKT_RTV
#define TUNNEL_PKT_RTV(p)
Definition: decode.h:976
source-af-packet.h
PKT_SRC_DECODER_VXLAN
@ PKT_SRC_DECODER_VXLAN
Definition: decode.h:59
mutex_lock_wait_ticks
thread_local uint64_t mutex_lock_wait_ticks
Packet_::next
struct Packet_ * next
Definition: decode.h:612
Packet_::flow_hash
uint32_t flow_hash
Definition: decode.h:483
Packet_::icmp_d
struct Packet_::@35::@43 icmp_d
Packet_::root
struct Packet_ * root
Definition: decode.h:627
DecodeThreadVars_::counter_pppoe
uint16_t counter_pppoe
Definition: decode.h:708
PacketAlerts_::suppressed
uint16_t suppressed
Definition: decode.h:308
PktProfilingPrefilterData_::size
uint32_t size
Definition: decode.h:389
DecodeThreadVars_::counter_mpls
uint16_t counter_mpls
Definition: decode.h:710
PKT_SRC_DETECT_RELOAD_FLUSH
@ PKT_SRC_DETECT_RELOAD_FLUSH
Definition: decode.h:60
PktProfilingData
struct PktProfilingData_ PktProfilingData
Packet_::pkt_src
uint8_t pkt_src
Definition: decode.h:588
ETHERNET_TYPE_PPPOE_SESS
#define ETHERNET_TYPE_PPPOE_SESS
Definition: decode-ethernet.h:42
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:672
PACKET_ENGINE_EVENT_MAX
#define PACKET_ENGINE_EVENT_MAX
Definition: decode.h:321
Packet_::recursion_level
uint8_t recursion_level
Definition: decode.h:467
PktProfilingLoggerData_
Definition: decode.h:377
PktProfiling_::tmm
PktProfilingTmmData tmm[TMM_SIZE]
Definition: decode.h:397
Signature_
Signature container.
Definition: detect.h:549
DecodeThreadVars_::output_flow_thread_data
void * output_flow_thread_data
Definition: decode.h:750
DecodeThreadVars_::counter_geneve
uint16_t counter_geneve
Definition: decode.h:701
ETHERNET_TYPE_ARP
#define ETHERNET_TYPE_ARP
Definition: decode-ethernet.h:35
DecodeThreadVars_::counter_max_mac_addrs_dst
uint16_t counter_max_mac_addrs_dst
Definition: decode.h:682
Packet_::pppoedh
PPPOEDiscoveryHdr * pppoedh
Definition: decode.h:576
DecodeThreadVarsAlloc
DecodeThreadVars * DecodeThreadVarsAlloc(ThreadVars *)
Alloc and setup DecodeThreadVars.
Definition: decode.c:684
DecodeThreadVars_::counter_defrag_max_hit
uint16_t counter_defrag_max_hit
Definition: decode.h:723
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:723
decode-chdlc.h
SC_ERR_DATALINK_UNIMPLEMENTED
@ SC_ERR_DATALINK_UNIMPLEMENTED
Definition: util-error.h:68
LINKTYPE_CISCO_HDLC
#define LINKTYPE_CISCO_HDLC
Definition: decode.h:1163
PktVar_::value_len
uint16_t value_len
Definition: decode.h:335
DECODE_EVENT_MAX
@ DECODE_EVENT_MAX
Definition: decode-events.h:292
app-layer-protos.h
DecodeThreadVars_::counter_null
uint16_t counter_null
Definition: decode.h:697
DecodeThreadVars_::counter_icmpv6
uint16_t counter_icmpv6
Definition: decode.h:693
Packet_::udph
UDPHdr * udph
Definition: decode.h:564
PcapPacketVars_
Definition: source-pcap.h:36
Packet_::drop_reason
uint8_t drop_reason
Definition: decode.h:624
Address_::family
char family
Definition: decode.h:123
Packet_::dst
Address dst
Definition: decode.h:447
PKT_SRC_DECODER_GRE
@ PKT_SRC_DECODER_GRE
Definition: decode.h:52
ENGINE_SET_INVALID_EVENT
#define ENGINE_SET_INVALID_EVENT(p, e)
Definition: decode.h:1077
PktProfilingTmmData_::ticks_start
uint64_t ticks_start
Definition: decode.h:344
PacketAlert_
Definition: decode.h:280
PktProfilingLoggerData_::ticks_spent
uint64_t ticks_spent
Definition: decode.h:380
DecodeThreadVars_::counter_flow_memcap
uint16_t counter_flow_memcap
Definition: decode.h:725
ETHERNET_TYPE_VLAN
#define ETHERNET_TYPE_VLAN
Definition: decode-vlan.h:31
DecodeThreadVars_::counter_defrag_ipv6_fragments
uint16_t counter_defrag_ipv6_fragments
Definition: decode.h:720
PKT_NOPACKET_INSPECTION
#define PKT_NOPACKET_INSPECTION
Definition: decode.h:1170
PktVar_
Definition: decode.h:329
AFPPacketVars_
per packet AF_PACKET vars
Definition: source-af-packet.h:144
PacketEngineEvents
struct PacketEngineEvents_ PacketEngineEvents
packet_alert_max
uint16_t packet_alert_max
Definition: decode.c:77
DecodeIEEE8021ah
int DecodeIEEE8021ah(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
PktProfilingDetectData_::ticks_start
uint64_t ticks_start
Definition: decode.h:368
likely
#define likely(expr)
Definition: util-optimize.h:32
PacketDefragPktSetupParent
void PacketDefragPktSetupParent(Packet *parent)
inform defrag "parent" that a pseudo packet is now associated to it.
Definition: decode.c:424
Packet_::plugin_v
uint8_t plugin_v[PLUGIN_VAR_SIZE]
Definition: decode.h:517
Packet_::ip6h
IPV6Hdr * ip6h
Definition: decode.h:542
Packet_::icmpv6vars
ICMPV6Vars icmpv6vars
Definition: decode.h:556
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:311
PktProfiling_::flowworker
PktProfilingData flowworker[PROFILE_FLOWWORKER_SIZE]
Definition: decode.h:398
mutex_lock_cnt
thread_local uint64_t mutex_lock_cnt
NFLOGPacketVars_
Definition: source-nflog.h:55
SigIntId
#define SigIntId
Definition: suricata-common.h:296
PacketAlerts_
Definition: decode.h:305
decode-vntag.h
Packet_::dp
Port dp
Definition: decode.h:457
PktVar_::key_len
uint16_t key_len
Definition: decode.h:334
PktProfilingAppData_
Definition: decode.h:373
Host_
Definition: host.h:58
Packet_::esph
ESPHdr * esph
Definition: decode.h:568
g_default_mtu
int g_default_mtu
Definition: suricata.c:225
DecodeThreadVars_::counter_flow_get_used_eval_reject
uint16_t counter_flow_get_used_eval_reject
Definition: decode.h:737
PktProfiling_::proto_detect
uint64_t proto_detect
Definition: decode.h:402
DecodePPPOESession
int DecodePPPOESession(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Main decoding function for PPPOE Session packets.
Definition: decode-pppoe.c:130
ETHERNET_TYPE_MPLS_MULTICAST
#define ETHERNET_TYPE_MPLS_MULTICAST
Definition: decode-mpls.h:30
Packet_::type
uint8_t type
Definition: decode.h:452
ETHERNET_TYPE_IP
#define ETHERNET_TYPE_IP
Definition: decode-ethernet.h:34
AppLayerDecoderEvents_::events
uint8_t * events
Definition: app-layer-events.h:36
SCMutex
#define SCMutex
Definition: threads-debug.h:114
DECODE_TUNNEL_UNSET
@ DECODE_TUNNEL_UNSET
Definition: decode.h:997
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:211
PktProfilingLoggerData_::ticks_start
uint64_t ticks_start
Definition: decode.h:378
PKT_DROP_REASON_FLOW_DROP
@ PKT_DROP_REASON_FLOW_DROP
Definition: decode.h:413
Packet_::src
Address src
Definition: decode.h:446
DecodeERSPANTypeI
int DecodeERSPANTypeI(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
ERSPAN Type I.
Definition: decode-erspan.c:65
DecodeCHDLC
int DecodeCHDLC(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Definition: decode-chdlc.c:42
DecodeUpdatePacketCounters
void DecodeUpdatePacketCounters(ThreadVars *tv, const DecodeThreadVars *dtv, const Packet *p)
Definition: decode.c:650
DecodeThreadVars_::counter_engine_events
uint16_t counter_engine_events[DECODE_EVENT_MAX]
Definition: decode.h:746
Packet_::tunnel_mutex
SCMutex tunnel_mutex
Definition: decode.h:637
LINKTYPE_ETHERNET
#define LINKTYPE_ETHERNET
Definition: decode.h:1154
Packet_::ip6eh
IPV6ExtHdrs ip6eh
Definition: decode.h:549
PktProfilingDetectData_::ticks_spent
uint64_t ticks_spent
Definition: decode.h:370
PktVar_::id
uint32_t id
Definition: decode.h:330
PACKET_TEST_ACTION
#define PACKET_TEST_ACTION(p, a)
Definition: decode.h:932
DCE_PKT_TOO_SMALL
@ DCE_PKT_TOO_SMALL
Definition: decode-events.h:206
PKT_DROP_REASON_DECODE_ERROR
@ PKT_DROP_REASON_DECODE_ERROR
Definition: decode.h:409
DecodeThreadVars_::counter_defrag_ipv4_fragments
uint16_t counter_defrag_ipv4_fragments
Definition: decode.h:717
PacketEngineEvents_::cnt
uint8_t cnt
Definition: decode.h:325
DecodePPPOEDiscovery
int DecodePPPOEDiscovery(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t)
Main decoding function for PPPOE Discovery packets.
Definition: decode-pppoe.c:50