suricata
detect.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2014 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 __DETECT_H__
25 #define __DETECT_H__
26 
27 #include "suricata-common.h"
28 
29 #include "flow.h"
30 
31 #include "detect-engine-proto.h"
32 #include "detect-reference.h"
33 #include "detect-metadata.h"
34 #include "detect-engine-register.h"
35 #include "packet-queue.h"
36 
37 #include "util-prefilter.h"
38 #include "util-mpm.h"
39 #include "util-spm.h"
40 #include "util-hash.h"
41 #include "util-hashlist.h"
42 #include "util-debug.h"
43 #include "util-error.h"
44 #include "util-radix-tree.h"
45 #include "util-file.h"
46 #include "reputation.h"
47 
48 #include "detect-mark.h"
49 
50 #include "stream.h"
51 
52 #include "util-var-name.h"
53 
54 #include "app-layer-events.h"
55 
56 #define DETECT_MAX_RULE_SIZE 8192
57 
58 #define DETECT_TRANSFORMS_MAX 16
59 
60 /* forward declarations for the structures from detect-engine-sigorder.h */
61 struct SCSigOrderFunc_;
63 
64 /*
65 
66  The detection engine groups similar signatures/rules together. Internally a
67  tree of different types of data is created on initialization. This is it's
68  global layout:
69 
70  For TCP/UDP
71 
72  - Flow direction
73  -- Protocol
74  -=- Src address
75  -==- Dst address
76  -===- Src port
77  -====- Dst port
78 
79  For the other protocols
80 
81  - Flow direction
82  -- Protocol
83  -=- Src address
84  -==- Dst address
85 
86 */
87 
88 /* holds the values for different possible lists in struct Signature.
89  * These codes are access points to particular lists in the array
90  * Signature->sm_lists[DETECT_SM_LIST_MAX]. */
94 
95  /* base64_data keyword uses some hardcoded logic so consider
96  * built-in
97  * TODO convert to inspect engine */
99 
100  /* list for post match actions: flowbit set, flowint increment, etc */
102 
103  DETECT_SM_LIST_TMATCH, /**< post-detection tagging */
104 
105  /* lists for alert thresholding and suppression */
108 
110 
111  /* start of dynamically registered lists */
113 };
114 
115 /* used for Signature->list, which indicates which list
116  * we're adding keywords to in cases of sticky buffers like
117  * file_data */
118 #define DETECT_SM_LIST_NOTSET INT_MAX
119 
120 /*
121  * DETECT ADDRESS
122  */
123 
124 /* a is ... than b */
125 enum {
126  ADDRESS_ER = -1, /**< error e.g. compare ipv4 and ipv6 */
127  ADDRESS_LT, /**< smaller [aaa] [bbb] */
128  ADDRESS_LE, /**< smaller with overlap [aa[bab]bb] */
129  ADDRESS_EQ, /**< exactly equal [abababab] */
130  ADDRESS_ES, /**< within [bb[aaa]bb] and [[abab]bbb] and [bbb[abab]] */
131  ADDRESS_EB, /**< completely overlaps [aa[bbb]aa] and [[baba]aaa] and [aaa[baba]] */
132  ADDRESS_GE, /**< bigger with overlap [bb[aba]aa] */
133  ADDRESS_GT, /**< bigger [bbb] [aaa] */
134 };
135 
136 #define ADDRESS_FLAG_NOT 0x01 /**< address is negated */
137 
138 /** \brief address structure for use in the detection engine.
139  *
140  * Contains the address information and matching information.
141  */
142 typedef struct DetectAddress_ {
143  /** address data for this group */
146 
147  /** flags affecting this address */
148  uint8_t flags;
149 
150  /** ptr to the previous address in the list */
152  /** ptr to the next address in the list */
154 } DetectAddress;
155 
156 /** Signature grouping head. Here 'any', ipv4 and ipv6 are split out */
157 typedef struct DetectAddressHead_ {
161 
162 
163 #include "detect-threshold.h"
164 
165 typedef struct DetectMatchAddressIPv4_ {
166  uint32_t ip; /**< address in host order, start of range */
167  uint32_t ip2; /**< address in host order, end of range */
169 
170 typedef struct DetectMatchAddressIPv6_ {
171  uint32_t ip[4];
172  uint32_t ip2[4];
174 
175 /*
176  * DETECT PORT
177  */
178 
179 /* a is ... than b */
180 enum {
181  PORT_ER = -1, /* error e.g. compare ipv4 and ipv6 */
182  PORT_LT, /* smaller [aaa] [bbb] */
183  PORT_LE, /* smaller with overlap [aa[bab]bb] */
184  PORT_EQ, /* exactly equal [abababab] */
185  PORT_ES, /* within [bb[aaa]bb] and [[abab]bbb] and [bbb[abab]] */
186  PORT_EB, /* completely overlaps [aa[bbb]aa] and [[baba]aaa] and [aaa[baba]] */
187  PORT_GE, /* bigger with overlap [bb[aba]aa] */
188  PORT_GT, /* bigger [bbb] [aaa] */
189 };
190 
191 #define PORT_FLAG_ANY 0x01 /**< 'any' special port */
192 #define PORT_FLAG_NOT 0x02 /**< negated port */
193 #define PORT_SIGGROUPHEAD_COPY 0x04 /**< sgh is a ptr copy */
194 
195 /** \brief Port structure for detection engine */
196 typedef struct DetectPort_ {
197  uint16_t port;
198  uint16_t port2;
199 
200  uint8_t flags; /**< flags for this port */
201 
202  /* signatures that belong in this group
203  *
204  * If the PORT_SIGGROUPHEAD_COPY flag is set, we don't own this pointer
205  * (memory is freed elsewhere).
206  */
207  struct SigGroupHead_ *sh;
208 
209  struct DetectPort_ *prev;
210  struct DetectPort_ *next;
211 } DetectPort;
212 
213 /* Signature flags */
214 /** \note: additions should be added to the rule analyzer as well */
215 
216 #define SIG_FLAG_SRC_ANY BIT_U32(0) /**< source is any */
217 #define SIG_FLAG_DST_ANY BIT_U32(1) /**< destination is any */
218 #define SIG_FLAG_SP_ANY BIT_U32(2) /**< source port is any */
219 #define SIG_FLAG_DP_ANY BIT_U32(3) /**< destination port is any */
220 
221 #define SIG_FLAG_NOALERT BIT_U32(4) /**< no alert flag is set */
222 #define SIG_FLAG_DSIZE BIT_U32(5) /**< signature has a dsize setting */
223 #define SIG_FLAG_APPLAYER BIT_U32(6) /**< signature applies to app layer instead of packets */
224 #define SIG_FLAG_IPONLY BIT_U32(7) /**< ip only signature */
225 
226 // vacancy
227 
228 #define SIG_FLAG_REQUIRE_PACKET BIT_U32(9) /**< signature is requiring packet match */
229 #define SIG_FLAG_REQUIRE_STREAM BIT_U32(10) /**< signature is requiring stream match */
230 
231 #define SIG_FLAG_MPM_NEG BIT_U32(11)
232 
233 #define SIG_FLAG_FLUSH BIT_U32(12) /**< detection logic needs stream flush notification */
234 
235 // vacancies
236 
237 #define SIG_FLAG_REQUIRE_FLOWVAR BIT_U32(17) /**< signature can only match if a flowbit, flowvar or flowint is available. */
238 
239 #define SIG_FLAG_FILESTORE BIT_U32(18) /**< signature has filestore keyword */
240 
241 #define SIG_FLAG_TOSERVER BIT_U32(19)
242 #define SIG_FLAG_TOCLIENT BIT_U32(20)
243 
244 #define SIG_FLAG_TLSSTORE BIT_U32(21)
245 
246 #define SIG_FLAG_BYPASS BIT_U32(22)
247 
248 #define SIG_FLAG_PREFILTER BIT_U32(23) /**< sig is part of a prefilter engine */
249 
250 /** Proto detect only signature.
251  * Inspected once per direction when protocol detection is done. */
252 #define SIG_FLAG_PDONLY BIT_U32(24)
253 /** Info for Source and Target identification */
254 #define SIG_FLAG_SRC_IS_TARGET BIT_U32(25)
255 /** Info for Source and Target identification */
256 #define SIG_FLAG_DEST_IS_TARGET BIT_U32(26)
257 
258 #define SIG_FLAG_HAS_TARGET (SIG_FLAG_DEST_IS_TARGET|SIG_FLAG_SRC_IS_TARGET)
259 
260 /* signature init flags */
261 #define SIG_FLAG_INIT_DEONLY (1<<0) /**< decode event only signature */
262 #define SIG_FLAG_INIT_PACKET (1<<1) /**< signature has matches against a packet (as opposed to app layer) */
263 #define SIG_FLAG_INIT_FLOW (1<<2) /**< signature has a flow setting */
264 #define SIG_FLAG_INIT_BIDIREC (1<<3) /**< signature has bidirectional operator */
265 #define SIG_FLAG_INIT_FIRST_IPPROTO_SEEN (1<<4) /** < signature has seen the first ip_proto keyword */
266 #define SIG_FLAG_INIT_HAS_TRANSFORM (1<<5)
267 #define SIG_FLAG_INIT_STATE_MATCH (1<<6) /**< signature has matches that require stateful inspection */
268 #define SIG_FLAG_INIT_NEED_FLUSH (1<<7)
269 
270 /* signature mask flags */
271 /** \note: additions should be added to the rule analyzer as well */
272 #define SIG_MASK_REQUIRE_PAYLOAD BIT_U8(0)
273 #define SIG_MASK_REQUIRE_FLOW BIT_U8(1)
274 #define SIG_MASK_REQUIRE_FLAGS_INITDEINIT BIT_U8(2) /* SYN, FIN, RST */
275 #define SIG_MASK_REQUIRE_FLAGS_UNUSUAL BIT_U8(3) /* URG, ECN, CWR */
276 #define SIG_MASK_REQUIRE_NO_PAYLOAD BIT_U8(4)
277 #define SIG_MASK_REQUIRE_DCERPC BIT_U8(5) /* require either SMB+DCE or raw DCE */
278 // vacancy
279 #define SIG_MASK_REQUIRE_ENGINE_EVENT BIT_U8(7)
280 
281 /* for now a uint8_t is enough */
282 #define SignatureMask uint8_t
283 
284 #define DETECT_ENGINE_THREAD_CTX_STREAM_CONTENT_MATCH 0x0004
285 
286 #define FILE_SIG_NEED_FILE 0x01
287 #define FILE_SIG_NEED_FILENAME 0x02
288 #define FILE_SIG_NEED_MAGIC 0x04 /**< need the start of the file */
289 #define FILE_SIG_NEED_FILECONTENT 0x08
290 #define FILE_SIG_NEED_MD5 0x10
291 #define FILE_SIG_NEED_SHA1 0x20
292 #define FILE_SIG_NEED_SHA256 0x40
293 #define FILE_SIG_NEED_SIZE 0x80
294 
295 /* Detection Engine flags */
296 #define DE_QUIET 0x01 /**< DE is quiet (esp for unittests) */
297 
298 typedef struct IPOnlyCIDRItem_ {
299  /* address data for this item */
300  uint8_t family;
301  /* netmask in CIDR values (ex. /16 /18 /24..) */
302  uint8_t netmask;
303  /* If this host or net is negated for the signum */
304  uint8_t negated;
305 
306  uint32_t ip[4];
307  SigIntId signum; /**< our internal id */
308 
309  /* linked list, the header should be the biggest network */
311 
313 
314 /** \brief Used to start a pointer to SigMatch context
315  * Should never be dereferenced without casting to something else.
316  */
317 typedef struct SigMatchCtx_ {
318  int foo;
319 } SigMatchCtx;
320 
321 /** \brief a single match condition for a signature */
322 typedef struct SigMatch_ {
323  uint8_t type; /**< match type */
324  uint16_t idx; /**< position in the signature */
325  SigMatchCtx *ctx; /**< plugin specific data */
326  struct SigMatch_ *next;
327  struct SigMatch_ *prev;
328 } SigMatch;
329 
330 /** \brief Data needed for Match() */
331 typedef struct SigMatchData_ {
332  uint8_t type; /**< match type */
333  uint8_t is_last; /**< Last element of the list */
334  SigMatchCtx *ctx; /**< plugin specific data */
335 } SigMatchData;
336 
337 struct DetectEngineThreadCtx_;// DetectEngineThreadCtx;
338 
339 /* inspection buffer is a simple structure that is passed between prefilter,
340  * transformation functions and inspection functions.
341  * Initialy setup with 'orig' ptr and len, transformations can then take
342  * then and fill the 'buf'. Multiple transformations can update the buffer,
343  * both growing and shrinking it.
344  * Prefilter and inspection will only deal with 'inspect'. */
345 
346 typedef struct InspectionBuffer {
347  const uint8_t *inspect; /**< active pointer, points either to ::buf or ::orig */
348  uint32_t inspect_len; /**< size of active data. See to ::len or ::orig_len */
349  uint64_t inspect_offset;
350 
351  uint8_t *buf;
352  uint32_t len; /**< how much is in use */
353  uint32_t size; /**< size of the memory allocation */
354 
355  const uint8_t *orig;
356  uint32_t orig_len;
358 
359 /* inspection buffers are kept per tx (in det_ctx), but some protocols
360  * need a bit more. A single TX might have multiple buffers, e.g. files in
361  * SMTP or DNS queries. Since all prefilters+transforms run before the
362  * individual rules need the same buffers, we need a place to store the
363  * transformed data. This array of arrays is that place. */
364 
367  uint32_t size; /**< size in number of elements */
368  uint32_t max:31; /**< max id in use in this run */
369  uint32_t init:1; /**< first time used this run. Used for clean logic */
371 
372 typedef struct DetectEngineTransforms {
373  int transforms[DETECT_TRANSFORMS_MAX];
374  int cnt;
376 
377 /** callback for getting the buffer we need to prefilter/inspect */
378 typedef InspectionBuffer *(*InspectionBufferGetDataPtr)(
379  struct DetectEngineThreadCtx_ *det_ctx,
380  const DetectEngineTransforms *transforms,
381  Flow *f, const uint8_t flow_flags,
382  void *txv, const int list_id);
383 
385  struct DetectEngineCtx_ *de_ctx, struct DetectEngineThreadCtx_ *det_ctx,
386  const struct Signature_ *sig, const SigMatchData *smd,
387  Flow *f, uint8_t flags, void *alstate,
388  void *tx, uint64_t tx_id);
389 
391 
392 typedef int (*InspectEngineFuncPtr2)(
393  struct DetectEngineCtx_ *de_ctx, struct DetectEngineThreadCtx_ *det_ctx,
394  const struct DetectEngineAppInspectionEngine_ *engine,
395  const struct Signature_ *s,
396  Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id);
397 
400  uint8_t dir;
401  uint8_t id; /**< per sig id used in state keeping */
402  uint16_t mpm:1;
403  uint16_t stream:1;
404  uint16_t sm_list:14;
405  int16_t progress;
406 
407  /* \retval 0 No match. Don't discontinue matching yet. We need more data.
408  * 1 Match.
409  * 2 Sig can't match.
410  * 3 Special value used by filestore sigs to indicate disabling
411  * filestore for the tx.
412  */
414 
415  struct {
418  /** pointer to the transforms in the 'DetectBuffer entry for this list */
420  } v2;
421 
423 
426 
427 typedef struct DetectBufferType_ {
428  const char *string;
429  const char *description;
430  int id;
432  _Bool mpm;
433  _Bool packet; /**< compat to packet matches */
435  void (*SetupCallback)(const struct DetectEngineCtx_ *, struct Signature_ *);
436  bool (*ValidateCallback)(const struct Signature_ *, const char **sigerror);
439 
440 #ifdef UNITTESTS
441 #define sm_lists init_data->smlists
442 #define sm_lists_tail init_data->smlists_tail
443 #endif
444 
445 typedef struct SignatureInitData_ {
446  /** Number of sigmatches. Used for assigning SigMatch::idx */
447  uint16_t sm_cnt;
448 
449  /** option was prefixed with '!'. Only set for sigmatches that
450  * have the SIGMATCH_HANDLE_NEGATION flag set. */
451  bool negated;
452 
453  /* track if we saw any negation in the addresses. If so, we
454  * skip it for ip-only */
457 
458  /* used to hold flags that are used during init */
459  uint32_t init_flags;
460  /* coccinelle: SignatureInitData:init_flags:SIG_FLAG_INIT_ */
461 
462  /* used at init to determine max dsize */
464 
465  /* the fast pattern added from this signature */
467  /* used to speed up init of prefilter */
469 
470  /* SigMatch list used for adding content and friends. E.g. file_data; */
471  int list;
472  bool list_set;
473 
474  int transforms[DETECT_TRANSFORMS_MAX];
476 
477  /** score to influence rule grouping. A higher value leads to a higher
478  * likelyhood of a rulegroup with this sig ending up as a contained
479  * group. */
481 
482  /** address settings for this signature */
484 
486 
488  /* holds all sm lists */
489  struct SigMatch_ **smlists;
490  /* holds all sm lists' tails */
493 
494 /** \brief Signature container */
495 typedef struct Signature_ {
496  uint32_t flags;
497  /* coccinelle: Signature:flags:SIG_FLAG_ */
498 
500 
501  uint16_t dsize_low;
502  uint16_t dsize_high;
503 
505  SigIntId num; /**< signature number, internal id */
506 
507  /** inline -- action */
508  uint8_t action;
509  uint8_t file_flags;
510 
511  /** addresses, ports and proto this sig matches on */
513 
514  /** classification id **/
515  uint8_t class;
516 
517  /** ipv4 match arrays */
524  /** ipv6 match arrays */
527 
528  uint32_t id; /**< sid, set by the 'sid' rule keyword */
529  uint32_t gid; /**< generator id */
530  uint32_t rev;
531  int prio;
532 
533  /** port settings for this signature */
534  DetectPort *sp, *dp;
535 
536 #ifdef PROFILING
537  uint16_t profiling_id;
538 #endif
539 
540  /** netblocks and hosts specified at the sid, in CIDR format */
542 
544 
545  /* Matching structures for the built-ins. The others are in
546  * their inspect engines. */
548 
549  /* memory is still owned by the sm_lists/sm_arrays entry */
551 
552  char *msg;
553 
554  /** classification message */
555  char *class_msg;
556  /** Reference */
558  /** Metadata */
560 
561  char *sig_str;
562 
564 
565  /** ptr to the next sig in the list */
566  struct Signature_ *next;
567 } Signature;
568 
569 /** \brief one time registration of keywords at start up */
571  const char *name;
572  char pname[32]; /**< name used in profiling */
573  int direction; /**< SIG_FLAG_TOSERVER or SIG_FLAG_TOCLIENT */
574  int sm_list;
575 
576  int (*PrefilterRegister)(struct DetectEngineCtx_ *de_ctx,
577  struct SigGroupHead_ *sgh, MpmCtx *mpm_ctx);
578 
579  int priority;
580 
581  struct {
582  int (*PrefilterRegisterWithListId)(struct DetectEngineCtx_ *de_ctx,
583  struct SigGroupHead_ *sgh, MpmCtx *mpm_ctx,
584  const struct DetectMpmAppLayerRegistery_ *mpm_reg, int list_id);
589  } v2;
590 
591  int id; /**< index into this array and result arrays */
592 
595 
596 /** \brief structure for storing per detect engine mpm keyword settings
597  */
600  int32_t sgh_mpm_context; /**< mpm factory id */
602 
603 typedef struct DetectReplaceList_ {
605  uint8_t *found;
608 
609 /** only execute flowvar storage if rule matched */
610 #define DETECT_VAR_TYPE_FLOW_POSTMATCH 1
611 #define DETECT_VAR_TYPE_PKT_POSTMATCH 2
612 
613 /** list for flowvar store candidates, to be stored from
614  * post-match function */
615 typedef struct DetectVarList_ {
616  uint32_t idx; /**< flowvar name idx */
617  uint16_t len; /**< data len */
618  uint16_t key_len;
619  int type; /**< type of store candidate POSTMATCH or ALWAYS */
620  uint8_t *key;
621  uint8_t *buffer; /**< alloc'd buffer, may be freed by
622  post-match, post-non-match */
624 } DetectVarList;
625 
627  uint8_t *sig_match_array; /* bit array of sig nums */
628  uint32_t sig_match_size; /* size in bytes of the array */
630 
631 /** \brief IP only rules matching ctx. */
632 typedef struct DetectEngineIPOnlyCtx_ {
633  /* lookup hashes */
634  HashListTable *ht16_src, *ht16_dst;
635  HashListTable *ht24_src, *ht24_dst;
636 
637  /* Lookup trees */
638  SCRadixTree *tree_ipv4src, *tree_ipv4dst;
639  SCRadixTree *tree_ipv6src, *tree_ipv6dst;
640 
641  /* Used to build the radix trees */
643 
644  /* counters */
645  uint32_t a_src_uniq16, a_src_total16;
646  uint32_t a_dst_uniq16, a_dst_total16;
647  uint32_t a_src_uniq24, a_src_total24;
648  uint32_t a_dst_uniq24, a_dst_total24;
649 
650  uint32_t max_idx;
651 
652  uint8_t *sig_init_array; /* bit array of sig nums */
653  uint32_t sig_init_size; /* size in bytes of the array */
654 
655  /* number of sigs in this head */
656  uint32_t sig_cnt;
657  uint32_t *match_array;
659 
660 typedef struct DetectEngineLookupFlow_ {
663  struct SigGroupHead_ *sgh[256];
665 
666 /* Flow status
667  *
668  * to server
669  * to client
670  */
671 #define FLOW_STATES 2
672 
673 /** \brief threshold ctx */
674 typedef struct ThresholdCtx_ {
675  SCMutex threshold_table_lock; /**< Mutex for hash table */
676 
677  /** to support rate_filter "by_rule" option */
679  uint32_t th_size;
680 } ThresholdCtx;
681 
682 typedef struct SigString_ {
683  char *filename;
684  char *sig_str;
685  char *sig_error;
686  int line;
688 } SigString;
689 
690 /** \brief Signature loader statistics */
691 typedef struct SigFileLoaderStat_ {
692  TAILQ_HEAD(, SigString_) failed_sigs;
698 
700  void *(*InitFunc)(void *);
701  void (*FreeFunc)(void *);
702  void *data;
704  int id;
705  const char *name; /* keyword name, for error printing */
707 
709 {
710  DETECT_PREFILTER_MPM = 0, /**< use only mpm / fast_pattern */
711  DETECT_PREFILTER_AUTO = 1, /**< use mpm + keyword prefilters */
712 };
713 
715 {
717  DETECT_ENGINE_TYPE_DD_STUB = 1, /* delayed detect stub: can be reloaded */
718  DETECT_ENGINE_TYPE_MT_STUB = 2, /* multi-tenant stub: cannot be reloaded */
720 };
721 
722 /** \brief main detection engine ctx */
723 typedef struct DetectEngineCtx_ {
724  uint8_t flags;
726 
728 
730  uint32_t sig_cnt;
731 
732  /* version of the srep data */
733  uint32_t srep_version;
734 
735  /* reputation for netblocks */
737 
739  uint32_t sig_array_size; /* size in bytes */
740  uint32_t sig_array_len; /* size in array members */
741 
742  uint32_t signum;
743 
744  /** Maximum value of all our sgh's non_mpm_store_cnt setting,
745  * used to alloc det_ctx::non_mpm_id_array */
747 
748  /* used by the signature ordering module */
750 
751  /* hash table used for holding the classification config info */
753  /* hash table used for holding the reference config info */
755 
756  /* main sigs */
758 
759  uint32_t gh_unique, gh_reuse;
760 
761  /* init phase vars */
763 
765 
766  /* hash table used to cull out duplicate sigs */
768 
771 
772  uint16_t mpm_matcher; /**< mpm matcher this ctx uses */
773  uint16_t spm_matcher; /**< spm matcher this ctx uses */
774 
775  /* spm thread context prototype, built as spm matchers are constructed and
776  * later used to construct thread context for each thread. */
778 
779  /* Config options */
780 
783 
784  /* specify the configuration for mpm context factory */
786 
787  /* max flowbit id that is used */
788  uint32_t max_fb_id;
789 
790  uint32_t max_fp_id;
791 
793 
794  /* maximum recursion depth for content inspection */
796 
797  /* conf parameter that limits the length of the http request body inspected */
799  /* conf parameter that limits the length of the http response body inspected */
801 
802  /* array containing all sgh's in use so we can loop
803  * through it in Stage4. */
805  uint32_t sgh_array_cnt;
806  uint32_t sgh_array_size;
807 
812 
813  /* the max local id used amongst all sigs */
815 
816  /** version of the detect engine */
817  uint32_t version;
818 
819  /** sgh for signatures that match against invalid packets. In those cases
820  * we can't lookup by proto, address, port as we don't have these */
822 
823  /* Maximum size of the buffer for decoded base64 data. */
825 
826  /** Store rule file and line so that parsers can use them in errors. */
827  char *rule_file;
829  const char *sigerror;
830 
831  /** list of keywords that need thread local ctxs */
834 
835  struct {
836  uint32_t content_limit;
839  } filedata_config[ALPROTO_MAX];
841 
842 #ifdef PROFILING
849 #endif
850  uint32_t prefilter_maxid;
851 
852  char config_prefix[64];
853 
855 
856  /** how many de_ctx' are referencing this */
857  uint32_t ref_cnt;
858  /** list in master: either active or freelist */
860 
861  /** id of loader thread 'owning' this de_ctx */
863 
864  /** are we useing just mpm or also other prefilters */
866 
868 
871 
872  /** table for storing the string representation with the parsers result */
874 
875  /** table to store metadata keys and values */
877 
880 
881  /* hash table with rule-time buffer registration. Start time registration
882  * is in detect-engine.c::g_buffer_type_hash */
885 
886  /* list with app inspect engines. Both the start-time registered ones and
887  * the rule-time registered ones. */
891 
892  uint32_t prefilter_id;
894 
895  /** table with mpms and their registration function
896  * \todo we only need this at init, so perhaps this
897  * can move to a DetectEngineCtx 'init' struct */
899 
900  /** time of last ruleset reload */
901  struct timeval last_reload;
902 
903  /** signatures stats */
905 
906  /** per keyword flag indicating if a prefilter has been
907  * set for it. If true, the setup function will have to
908  * run. */
909  bool sm_types_prefilter[DETECT_TBLSIZE];
910 
912 
913 /* Engine groups profiles (low, medium, high, custom) */
914 enum {
921 };
922 
923 /* Siggroup mpm context profile */
924 enum {
928 };
929 
930 typedef struct HttpReassembledBody_ {
931  const uint8_t *buffer;
933  uint32_t buffer_size; /**< size of the buffer itself */
934  uint32_t buffer_len; /**< data len in the buffer */
936  uint64_t offset; /**< data offset */
938 
939 #define DETECT_FILESTORE_MAX 15
940 
944  uint8_t alproto;
946 
947 /** array of TX inspect rule candidates */
948 typedef struct RuleMatchCandidateTx {
949  SigIntId id; /**< internal signature id */
950  uint32_t *flags; /**< inspect flags ptr */
951  union {
952  struct {
954  uint8_t stream_result;
955  };
956  uint32_t stream_reset;
957  };
958 
959  const Signature *s; /**< ptr to sig */
961 
962 /**
963  * Detection engine thread data.
964  */
965 typedef struct DetectEngineThreadCtx_ {
966  /** \note multi-tenant hash lookup code from Detect() *depends*
967  * on this beeing the first member */
968  uint32_t tenant_id;
969 
970  /** ticker that is incremented once per packet. */
971  uint64_t ticker;
972 
973  /* the thread to which this detection engine thread belongs */
975 
977  uint32_t non_pf_id_cnt; // size is cnt * sizeof(uint32_t)
978 
979  uint32_t mt_det_ctxs_cnt;
982 
985 
986  uint32_t (*TenantGetId)(const void *, const Packet *p);
987 
988  /* detection engine variables */
989 
991 
992  /** offset into the payload of the last match by:
993  * content, pcre, etc */
994  uint32_t buffer_offset;
995  /* used by pcre match function alone */
997 
998  /* counter for the filestore array below -- up here for cache reasons. */
999  uint16_t filestore_cnt;
1000 
1001  /** id for alert counter */
1002  uint16_t counter_alerts;
1003 #ifdef PROFILING
1008 #endif
1009 
1010  int inspect_list; /**< list we're currently inspecting, DETECT_SM_LIST_* */
1011 
1012  struct {
1014  uint32_t buffers_size; /**< in number of elements */
1015  uint32_t to_clear_idx;
1016  uint32_t *to_clear_queue;
1017  } inspect;
1018 
1019  struct {
1020  /** inspection buffers for more complex case. As we can inspect multiple
1021  * buffers in parallel, we need this extra wrapper struct */
1023  uint32_t buffers_size; /**< in number of elements */
1024  uint32_t to_clear_idx;
1025  uint32_t *to_clear_queue;
1026  } multi_inspect;
1027 
1028  /* used to discontinue any more matching */
1030  uint16_t flags;
1031 
1032  /* bool: if tx_id is set, this is 1, otherwise 0 */
1033  uint16_t tx_id_set;
1034  /** ID of the transaction currently being inspected. */
1035  uint64_t tx_id;
1037 
1038  SC_ATOMIC_DECLARE(int, so_far_used_by_detect);
1039 
1040  /* holds the current recursion depth on content inspection */
1042 
1043  /** array of signature pointers we're going to inspect in the detection
1044  * loop. */
1046  /** size of the array in items (mem size if * sizeof(Signature *)
1047  * Only used during initialization. */
1049  /** size in use */
1051 
1054 
1057 
1058  /** pointer to the current mpm ctx that is stored
1059  * in a rule group head -- can be either a content
1060  * or uricontent ctx. */
1061  MpmThreadCtx mtc; /**< thread ctx for the mpm */
1062  MpmThreadCtx mtcu; /**< thread ctx for uricontent mpm */
1063  MpmThreadCtx mtcs; /**< thread ctx for stream mpm */
1065 
1066  /** SPM thread context used for scanning. This has been cloned from the
1067  * prototype held by DetectEngineCtx. */
1069 
1070  /** ip only rules ctx */
1072 
1073  /* byte jump values */
1074  uint64_t *bj_values;
1075 
1076  /* string to replace */
1078  /* vars to store in post match function */
1080 
1081  /* Array in which the filestore keyword stores file id and tx id. If the
1082  * full signature matches, these are processed by a post-match filestore
1083  * function to finalize the store. */
1084  struct {
1085  uint32_t file_id;
1086  uint64_t tx_id;
1087  } filestore[DETECT_FILESTORE_MAX];
1088 
1090  /** store for keyword contexts that need a per thread storage. Per de_ctx. */
1093  /** store for keyword contexts that need a per thread storage. Global. */
1096 
1097  uint8_t *base64_decoded;
1100 
1102  uint16_t events;
1103 
1104 #ifdef DEBUG
1105  uint64_t pkt_stream_add_cnt;
1106  uint64_t payload_mpm_cnt;
1107  uint64_t payload_mpm_size;
1108  uint64_t stream_mpm_cnt;
1109  uint64_t stream_mpm_size;
1110  uint64_t payload_persig_cnt;
1111  uint64_t payload_persig_size;
1112  uint64_t stream_persig_cnt;
1113  uint64_t stream_persig_size;
1114 #endif
1115 #ifdef PROFILING
1120  int keyword_perf_list; /**< list we're currently inspecting, DETECT_SM_LIST_* */
1122 
1125 #endif
1127 
1128 /** \brief element in sigmatch type table.
1129  */
1130 typedef struct SigTableElmt_ {
1131  /** Packet match function pointer */
1132  int (*Match)(ThreadVars *, DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *);
1133 
1134  /** AppLayer TX match function pointer */
1135  int (*AppLayerTxMatch)(ThreadVars *, DetectEngineThreadCtx *, Flow *,
1136  uint8_t flags, void *alstate, void *txv,
1137  const Signature *, const SigMatchCtx *);
1138 
1139  /** File match function pointer */
1140  int (*FileMatch)(ThreadVars *, /**< thread local vars */
1141  DetectEngineThreadCtx *,
1142  Flow *, /**< *LOCKED* flow */
1143  uint8_t flags, File *, const Signature *, const SigMatchCtx *);
1144 
1145  /** InspectionBuffer transformation callback */
1146  void (*Transform)(InspectionBuffer *);
1147 
1148  /** keyword setup function pointer */
1149  int (*Setup)(DetectEngineCtx *, Signature *, const char *);
1150 
1151  _Bool (*SupportsPrefilter)(const Signature *s);
1152  int (*SetupPrefilter)(DetectEngineCtx *de_ctx, struct SigGroupHead_ *sgh);
1153 
1154  void (*Free)(void *);
1155  void (*RegisterTests)(void);
1156 
1157  uint16_t flags;
1158  /* coccinelle: SigTableElmt:flags:SIGMATCH_ */
1159 
1160  /** better keyword to replace the current one */
1161  uint16_t alternative;
1162 
1163  const char *name; /**< keyword name alias */
1164  const char *alias; /**< name alias */
1165  const char *desc;
1166  const char *url;
1167 
1168 } SigTableElmt;
1169 
1170 /* event code */
1171 enum {
1172 #ifdef UNITTESTS
1174 #endif
1189 };
1190 
1191 #define SIG_GROUP_HEAD_HAVERAWSTREAM BIT_U32(0)
1192 #ifdef HAVE_MAGIC
1193 #define SIG_GROUP_HEAD_HAVEFILEMAGIC BIT_U32(20)
1194 #endif
1195 #define SIG_GROUP_HEAD_HAVEFILEMD5 BIT_U32(21)
1196 #define SIG_GROUP_HEAD_HAVEFILESIZE BIT_U32(22)
1197 #define SIG_GROUP_HEAD_HAVEFILESHA1 BIT_U32(23)
1198 #define SIG_GROUP_HEAD_HAVEFILESHA256 BIT_U32(24)
1199 
1209 };
1210 
1211 typedef struct MpmStore_ {
1212  uint8_t *sid_array;
1213  uint32_t sid_array_size;
1214 
1216  enum MpmBuiltinBuffers buffer;
1217  int sm_list;
1219 
1221 
1222 } MpmStore;
1223 
1224 typedef struct PrefilterEngineList_ {
1225  uint16_t id;
1226 
1227  /** App Proto this engine applies to: only used with Tx Engines */
1229  /** Minimal Tx progress we need before running the engine. Only used
1230  * with Tx Engine */
1232 
1233  /** Context for matching. Might be MpmCtx for MPM engines, other ctx'
1234  * for other engines. */
1235  void *pectx;
1236 
1237  void (*Prefilter)(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx);
1238  void (*PrefilterTx)(DetectEngineThreadCtx *det_ctx, const void *pectx,
1239  Packet *p, Flow *f, void *tx,
1240  const uint64_t idx, const uint8_t flags);
1241 
1243 
1244  /** Free function for pectx data. If NULL the memory is not freed. */
1245  void (*Free)(void *pectx);
1246 
1247  const char *name;
1248  /* global id for this prefilter */
1249  uint32_t gid;
1251 
1252 typedef struct PrefilterEngine_ {
1253  uint16_t local_id;
1254 
1255  /** App Proto this engine applies to: only used with Tx Engines */
1257  /** Minimal Tx progress we need before running the engine. Only used
1258  * with Tx Engine */
1260 
1261  /** Context for matching. Might be MpmCtx for MPM engines, other ctx'
1262  * for other engines. */
1263  void *pectx;
1264 
1265  union {
1266  void (*Prefilter)(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx);
1267  void (*PrefilterTx)(DetectEngineThreadCtx *det_ctx, const void *pectx,
1268  Packet *p, Flow *f, void *tx,
1269  const uint64_t idx, const uint8_t flags);
1270  } cb;
1271 
1272  /* global id for this prefilter */
1273  uint32_t gid;
1274  int is_last;
1275 } PrefilterEngine;
1276 
1277 typedef struct SigGroupHeadInitData_ {
1278  MpmStore mpm_store[MPMB_MAX];
1279 
1280  uint8_t *sig_array; /**< bit array of sig nums (internal id's) */
1281  uint32_t sig_size; /**< size in bytes */
1282 
1283  uint8_t protos[256]; /**< proto(s) this sgh is for */
1284  uint32_t direction; /**< set to SIG_FLAG_TOSERVER, SIG_FLAG_TOCLIENT or both */
1285  int whitelist; /**< try to make this group a unique one */
1286 
1288 
1292 
1293  /* port ptr */
1296 
1297 /** \brief Container for matching data for a signature group */
1298 typedef struct SigGroupHead_ {
1299  uint32_t flags;
1300  /* coccinelle: SigGroupHead:flags:SIG_GROUP_HEAD_ */
1301 
1302  /* number of sigs in this head */
1304 
1305  /* non prefilter list excluding SYN rules */
1308  SignatureNonPrefilterStore *non_pf_other_store_array; // size is non_mpm_store_cnt * sizeof(SignatureNonPrefilterStore)
1309  /* non mpm list including SYN rules */
1310  SignatureNonPrefilterStore *non_pf_syn_store_array; // size is non_mpm_syn_store_cnt * sizeof(SignatureNonPrefilterStore)
1311 
1312  /** the number of signatures in this sgh that have the filestore keyword
1313  * set. */
1314  uint16_t filestore_cnt;
1315 
1316  uint32_t id; /**< unique id used to index sgh_array for stats */
1317 
1321 
1322  /** Array with sig ptrs... size is sig_cnt * sizeof(Signature *) */
1324 
1325  /* ptr to our init data we only use at... init :) */
1327 
1328 } SigGroupHead;
1329 
1330 /** sigmatch has no options, so the parser shouldn't expect any */
1331 #define SIGMATCH_NOOPT BIT_U16(0)
1332 /** sigmatch is compatible with a ip only rule */
1333 #define SIGMATCH_IPONLY_COMPAT BIT_U16(1)
1334 /** sigmatch is compatible with a decode event only rule */
1335 #define SIGMATCH_DEONLY_COMPAT BIT_U16(2)
1336 /**< Flag to indicate that the signature is not built-in */
1337 #define SIGMATCH_NOT_BUILT BIT_U16(3)
1338 /** sigmatch may have options, so the parser should be ready to
1339  * deal with both cases */
1340 #define SIGMATCH_OPTIONAL_OPT BIT_U16(4)
1341 /** input may be wrapped in double quotes. They will be stripped before
1342  * input data is passed to keyword parser */
1343 #define SIGMATCH_QUOTES_OPTIONAL BIT_U16(5)
1344 /** input MUST be wrapped in double quotes. They will be stripped before
1345  * input data is passed to keyword parser. Missing double quotes lead to
1346  * error and signature invalidation. */
1347 #define SIGMATCH_QUOTES_MANDATORY BIT_U16(6)
1348 /** negation parsing is handled by the rule parser. Signature::init_data::negated
1349  * will be set to true or false prior to calling the keyword parser. Exclamation
1350  * mark is stripped from the input to the keyword parser. */
1351 #define SIGMATCH_HANDLE_NEGATION BIT_U16(7)
1352 /** keyword is a content modifier */
1353 #define SIGMATCH_INFO_CONTENT_MODIFIER BIT_U16(8)
1354 /** keyword is a sticky buffer */
1355 #define SIGMATCH_INFO_STICKY_BUFFER BIT_U16(9)
1356 
1358 {
1359  TENANT_SELECTOR_UNKNOWN = 0, /**< not set */
1360  TENANT_SELECTOR_DIRECT, /**< method provides direct tenant id */
1361  TENANT_SELECTOR_VLAN, /**< map vlan to tenant id */
1362  TENANT_SELECTOR_LIVEDEV, /**< map livedev to tenant id */
1363 };
1364 
1366  uint32_t tenant_id;
1367 
1368  /* traffic id that maps to the tenant id */
1369  uint32_t traffic_id;
1370 
1373 
1374 typedef struct DetectEngineMasterCtx_ {
1376 
1377  /** enable multi tenant mode */
1379 
1380  /** version, incremented after each 'apply to threads' */
1381  uint32_t version;
1382 
1383  /** list of active detection engines. This list is used to generate the
1384  * threads det_ctx's */
1386 
1387  /** free list, containing detection engines that will be removed but may
1388  * still be referenced by det_ctx's. Freed as soon as all references are
1389  * gone. */
1391 
1392  enum DetectEngineTenantSelectors tenant_selector;
1393 
1394  /** list of tenant mappings. Updated under lock. Used to generate lookup
1395  * structures. */
1397 
1398  /** list of keywords that need thread local ctxs,
1399  * only updated by keyword registration at start up. Not
1400  * covered by the lock. */
1404 
1405 /* Table with all SigMatch registrations */
1407 
1408 /** Remember to add the options in SignatureIsIPOnly() at detect.c otherwise it wont be part of a signature group */
1409 
1410 /* detection api */
1411 TmEcode Detect(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQueue *postpq);
1412 
1413 SigMatch *SigMatchAlloc(void);
1414 Signature *SigFindSignatureBySidGid(DetectEngineCtx *, uint32_t, uint32_t);
1416  Packet *, SignatureMask,
1417  uint16_t);
1418 void SigMatchFree(SigMatch *sm);
1419 
1420 void SigRegisterTests(void);
1421 void TmModuleDetectRegister (void);
1422 
1424 
1426 char *DetectLoadCompleteSigPath(const DetectEngineCtx *, const char *sig_file);
1427 int SigLoadSignatures (DetectEngineCtx *, char *, int);
1428 void SigMatchSignatures(ThreadVars *th_v, DetectEngineCtx *de_ctx,
1429  DetectEngineThreadCtx *det_ctx, Packet *p);
1430 
1431 int SignatureIsIPOnly(DetectEngineCtx *de_ctx, const Signature *s);
1432 const SigGroupHead *SigMatchSignaturesGetSgh(const DetectEngineCtx *de_ctx, const Packet *p);
1433 
1435 
1436 
1437 int DetectRegisterThreadCtxFuncs(DetectEngineCtx *, const char *name, void *(*InitFunc)(void *), void *data, void (*FreeFunc)(void *), int);
1439 
1440 void DetectSignatureApplyActions(Packet *p, const Signature *s, const uint8_t);
1441 
1442 void RuleMatchCandidateTxArrayInit(DetectEngineThreadCtx *det_ctx, uint32_t size);
1444 
1446 
1449 
1450 /* events */
1451 void DetectEngineSetEvent(DetectEngineThreadCtx *det_ctx, uint8_t e);
1453 int DetectEngineGetEventInfo(const char *event_name, int *event_id,
1455 
1456 #include "detect-engine-build.h"
1457 #include "detect-engine-register.h"
1458 
1459 #endif /* __DETECT_H__ */
1460 
struct DetectEngineTenantMapping_ DetectEngineTenantMapping
int DetectMetadataHashInit(DetectEngineCtx *de_ctx)
void ** keyword_ctxs_array
Definition: detect.h:1091
uint16_t filestore_cnt
Definition: detect.h:1314
struct DetectEngineTenantMapping_ * next
Definition: detect.h:1371
uint16_t profiling_id
Definition: detect.h:537
struct SCProfileSghData_ * sgh_perf_data
Definition: detect.h:1121
#define SCMutex
DetectReference * references
Definition: detect.h:557
MpmThreadCtx mtcs
Definition: detect.h:1063
enum AppLayerEventType_ AppLayerEventType
const char * description
Definition: detect.h:429
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect.h:1406
SignatureNonPrefilterStore * non_pf_syn_store_array
Definition: detect.h:1310
DetectProto proto
Definition: detect.h:512
uint16_t sm_cnt
Definition: detect.h:447
SigIntId sig_cnt
Definition: detect.h:1303
SignatureInitData * init_data
Definition: detect.h:563
int SigLoadSignatures(DetectEngineCtx *, char *, int)
Load signatures.
SCRadixTree * tree_ipv6src
Definition: detect.h:639
SpmGlobalThreadCtx * spm_global_thread_ctx
Definition: detect.h:777
InspectionBufferGetDataPtr GetData
Definition: detect.h:416
DetectMetadata * metadata
Definition: detect.h:559
SigMatch * dsize_sm
Definition: detect.h:463
DetectEnginePrefilterSetting
Definition: detect.h:708
Signature * SigFindSignatureBySidGid(DetectEngineCtx *, uint32_t, uint32_t)
Find a specific signature by sid and gid.
Signature ** sig_array
Definition: detect.h:738
uint32_t tx_candidates_size
Definition: detect.h:1053
struct DetectAddress_ DetectAddress
address structure for use in the detection engine.
#define SC_ATOMIC_DECLARE(type, name)
wrapper to declare an atomic variable including a (spin) lock to protect it.
Definition: util-atomic.h:56
struct DetectEngineAppInspectionEngine_ DetectEngineAppInspectionEngine
struct DetectAddress_ * prev
Definition: detect.h:151
struct DetectMatchAddressIPv6_ DetectMatchAddressIPv6
#define SignatureMask
Definition: detect.h:282
uint32_t sig_array_len
Definition: detect.h:740
int32_t sgh_mpm_context
Definition: detect.h:1218
InspectionBuffer * inspection_buffers
Definition: detect.h:366
uint16_t spm_matcher
Definition: detect.h:773
Signature loader statistics.
Definition: detect.h:691
const Signature * s
Definition: detect.h:959
int32_t byte_extract_max_local_id
Definition: detect.h:814
uint32_t tenant_array_size
Definition: detect.h:984
uint16_t dsize_high
Definition: detect.h:502
uint32_t buffer_len
Definition: detect.h:934
struct DetectEngineLookupFlow_ DetectEngineLookupFlow
SigMatch * prefilter_sm
Definition: detect.h:468
const char * string
Definition: detect.h:428
uint32_t non_pf_store_cnt
Definition: detect.h:1056
uint16_t discontinue_matching
Definition: detect.h:1029
uint32_t flags
Definition: detect.h:496
uint32_t event_type
uint32_t * match_array
Definition: detect.h:657
char * msg
Definition: detect.h:552
uint32_t max_fb_id
Definition: detect.h:788
int DetectEngineGetEventInfo(const char *event_name, int *event_id, AppLayerEventType *event_type)
uint32_t id
Definition: detect.h:528
struct SigGroupHead_ * sh
Definition: detect.h:207
int hcbd_buffer_limit
Definition: detect.h:798
Signature ** match_array
Definition: detect.h:1323
struct DetectAddressHead_ DetectAddressHead
uint32_t sid_array_size
Definition: detect.h:1213
uint64_t * bj_values
Definition: detect.h:1074
uint32_t non_pf_other_store_cnt
Definition: detect.h:1306
uint16_t counter_fnonmpm_list
Definition: detect.h:1006
DetectPort * tcp_whitelist
Definition: detect.h:869
void DisableDetectFlowFileFlags(Flow *f)
disable file features we don&#39;t need Called if we have no detection engine.
Definition: detect.c:1733
Address ip
Definition: detect.h:144
uint8_t is_last
Definition: detect.h:333
ThreadVars * tv
Definition: detect.h:974
struct SigMatch_ SigMatch
a single match condition for a signature
HashTable * class_conf_ht
Definition: detect.h:752
struct InspectionBuffer InspectionBuffer
struct DetectEngineThreadCtx_ ** mt_det_ctxs
Definition: detect.h:980
void SigMatchSignatures(ThreadVars *th_v, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1743
uint8_t netmask
Definition: detect.h:302
DetectPort * udp_whitelist
Definition: detect.h:870
DetectMpmAppLayerKeyword * app_mpms
Definition: detect.h:898
struct SignatureInitData_ SignatureInitData
int prio
Definition: detect.h:531
address structure for use in the detection engine.
Definition: detect.h:142
void SigAddressPrepareBidirectionals(DetectEngineCtx *)
InspectionBufferGetDataPtr GetData
Definition: detect.h:585
struct SigMatch_ * prev
Definition: detect.h:327
struct DetectPort_ * port
Definition: detect.h:1294
uint16_t key_len
Definition: detect.h:618
uint8_t * sig_init_array
Definition: detect.h:652
Signature * sig_list
Definition: detect.h:729
int buffer_type_id
Definition: detect.h:884
one time registration of keywords at start up
Definition: detect.h:570
int32_t sgh_mpm_context_proto_tcp_packet
Definition: detect.h:808
uint8_t * sid_array
Definition: detect.h:1212
uint32_t match_array_len
Definition: detect.h:1048
uint32_t size
Definition: detect.h:353
IPOnlyCIDRItem * ip_src
Definition: detect.h:642
RuleMatchCandidateTx * tx_candidates
Definition: detect.h:1052
DetectEngineThreadKeywordCtxItem * keyword_list
Definition: detect.h:832
uint32_t sig_array_size
Definition: detect.h:739
IPOnlyCIDRItem * CidrSrc
Definition: detect.h:541
uint32_t non_pf_store_cnt_max
Definition: detect.h:746
SigIntId * non_pf_id_array
Definition: detect.h:976
int DetectRegisterThreadCtxFuncs(DetectEngineCtx *, const char *name, void *(*InitFunc)(void *), void *data, void(*FreeFunc)(void *), int)
Register Thread keyword context Funcs.
void TmModuleDetectRegister(void)
struct DetectEngineTransforms DetectEngineTransforms
DetectReplaceList * replist
Definition: detect.h:1077
int SignatureIsIPOnly(DetectEngineCtx *de_ctx, const Signature *s)
Test is a initialized signature is IP only.
struct DetectMatchAddressIPv4_ DetectMatchAddressIPv4
Data needed for Match()
Definition: detect.h:331
struct SCProfileKeywordData_ * keyword_perf_data
Definition: detect.h:1118
struct DetectVarList_ DetectVarList
uint16_t len
Definition: detect.h:617
uint32_t content_inspect_window
Definition: detect.h:838
struct SCProfileData_ * rule_perf_data
Definition: detect.h:1116
DetectEngineTransforms transforms
Definition: detect.h:437
uint32_t to_clear_idx
Definition: detect.h:1015
Container for matching data for a signature group.
Definition: detect.h:1298
uint32_t srep_version
Definition: detect.h:733
MpmThreadCtx mtc
Definition: detect.h:1061
element in sigmatch type table.
Definition: detect.h:1130
struct DetectMpmAppLayerRegistery_ DetectMpmAppLayerRegistery
one time registration of keywords at start up
uint32_t orig_len
Definition: detect.h:356
uint32_t buffer_offset
Definition: detect.h:994
#define TAILQ_HEAD(name, type)
Definition: queue.h:321
struct InspectionBufferMultipleForList InspectionBufferMultipleForList
#define DETECT_FILESTORE_MAX
Definition: detect.h:939
uint32_t non_pf_syn_store_cnt
Definition: detect.h:1307
struct IPOnlyCIDRItem_ IPOnlyCIDRItem
InspectionBuffer * buffers
Definition: detect.h:1013
const char * name
Definition: detect.h:1163
uint16_t AppProto
struct DetectPort_ DetectPort
Port structure for detection engine.
void SigMatchSignaturesBuildMatchArray(DetectEngineThreadCtx *, Packet *, SignatureMask, uint16_t)
Signature container.
Definition: detect.h:495
struct PrefilterEngine_ PrefilterEngine
#define DETECT_TRANSFORMS_MAX
Definition: detect.h:58
PrefilterEngineList * tx_engines
Definition: detect.h:1291
void SigMatchFree(SigMatch *sm)
free a SigMatch
Definition: detect-parse.c:247
int32_t sgh_mpm_context_proto_other_packet
Definition: detect.h:810
uint8_t action
Definition: detect.h:508
HashListTable * mpm_hash_table
Definition: detect.h:764
int sm_list
Definition: detect.h:1217
void DetectEngineSetEvent(DetectEngineThreadCtx *det_ctx, uint8_t e)
uint16_t addr_src_match6_cnt
Definition: detect.h:521
uint32_t * to_clear_queue
Definition: detect.h:1016
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:317
const char * sigerror
Definition: detect.h:829
uint32_t id
Definition: detect.h:1316
uint32_t signum
Definition: detect.h:742
struct SigGroupHead_ * decoder_event_sgh
Definition: detect.h:821
struct DetectEngineTenantMapping_ * tenant_array
Definition: detect.h:983
int(* InspectEngineFuncPtr)(ThreadVars *tv, struct DetectEngineCtx_ *de_ctx, struct DetectEngineThreadCtx_ *det_ctx, const struct Signature_ *sig, const SigMatchData *smd, Flow *f, uint8_t flags, void *alstate, void *tx, uint64_t tx_id)
Definition: detect.h:384
Signature metadata list.
structure for storing per detect engine mpm keyword settings
Definition: detect.h:598
uint32_t content_inspect_min_size
Definition: detect.h:837
void RuleMatchCandidateTxArrayInit(DetectEngineThreadCtx *det_ctx, uint32_t size)
Definition: detect.c:1039
struct DetectEngineMasterCtx_ DetectEngineMasterCtx
struct MpmStore_ MpmStore
DetectMatchAddressIPv6 * addr_dst_match6
Definition: detect.h:525
SigIntId num
Definition: detect.h:505
struct SigMatch_ * next
Definition: detect.h:326
main detection engine ctx
Definition: detect.h:723
void * pectx
Definition: detect.h:1263
struct Signature_ Signature
Signature container.
uint16_t addr_src_match4_cnt
Definition: detect.h:519
PrefilterEngine * tx_engines
Definition: detect.h:1320
uint32_t max_fp_id
Definition: detect.h:790
MpmBuiltinBuffers
Definition: detect.h:1200
struct DetectMpmAppLayerRegistery_ * next
Definition: detect.h:593
int(* InspectEngineFuncPtr2)(struct DetectEngineCtx_ *de_ctx, struct DetectEngineThreadCtx_ *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, const struct Signature_ *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Definition: detect.h:392
SCMutex threshold_table_lock
Definition: detect.h:675
void * DetectThreadCtxGetKeywordThreadCtx(DetectEngineThreadCtx *, int)
Retrieve thread local keyword ctx by id.
DetectPort * udp
Definition: detect.h:662
const uint8_t * orig
Definition: detect.h:355
PrefilterEngine * pkt_engines
Definition: detect.h:1318
struct DetectPort_ * prev
Definition: detect.h:209
bool src_contains_negation
Definition: detect.h:455
HashListTable * buffer_type_hash
Definition: detect.h:883
struct HttpReassembledBody_ HttpReassembledBody
DetectMatchAddressIPv4 * addr_dst_match4
Definition: detect.h:522
uint32_t sgh_array_cnt
Definition: detect.h:805
DetectVarList * varlist
Definition: detect.h:1079
bool filedata_config_initialized
Definition: detect.h:840
struct DetectAddress_ * next
Definition: detect.h:153
DetectEngineCtx * free_list
Definition: detect.h:1390
void DetectFlowbitsAnalyze(DetectEngineCtx *de_ctx)
uint16_t dst
uint16_t local_id
Definition: detect.h:1253
Data structure to store app layer decoder events.
DetectMatchAddressIPv6 * addr_src_match6
Definition: detect.h:526
struct DetectVarList_ * next
Definition: detect.h:623
SigMatch * SigMatchAlloc(void)
Definition: detect-parse.c:232
uint16_t max_uniq_toserver_groups
Definition: detect.h:782
HashListTable * address_table
Definition: detect.h:873
uint8_t flags
Definition: detect.h:148
Signature wrapper used by signature ordering module while ordering signatures.
int32_t sgh_mpm_context_stream
Definition: detect.h:811
struct SCProfileSghDetectCtx_ * profile_sgh_ctx
Definition: detect.h:847
uint8_t * key
Definition: detect.h:620
DetectPort * tcp
Definition: detect.h:661
DetectEngineTenantSelectors
Definition: detect.h:1357
char * rule_file
Definition: detect.h:827
uint8_t flags
Definition: detect.h:724
uint16_t filestore_cnt
Definition: detect.h:999
uint64_t inspect_offset
Definition: detect.h:349
int direction
Definition: detect.h:1215
MpmCtx ** app_mpms
Definition: detect.h:1287
SCRadixTree * tree_ipv4src
Definition: detect.h:638
uint8_t type
struct DetectEngineAppInspectionEngine_ * next
Definition: detect.h:424
uint16_t counter_alerts
Definition: detect.h:1002
void Prefilter(DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, Packet *p, const uint8_t flags)
const uint8_t * buffer
Definition: detect.h:931
DetectMatchAddressIPv4 * addr_src_match4
Definition: detect.h:523
char * filename
Definition: detect.h:683
HashListTable * ht24_src
Definition: detect.h:635
struct DetectEngineCtx_ DetectEngineCtx
main detection engine ctx
MpmCtxFactoryContainer * mpm_ctx_factory_container
Definition: detect.h:792
uint32_t buffer_size
Definition: detect.h:933
bool dst_contains_negation
Definition: detect.h:456
uint16_t mpm_matcher
Definition: detect.h:772
char * DetectLoadCompleteSigPath(const DetectEngineCtx *, const char *sig_file)
Create the path if default-rule-path was specified.
HashListTable * sgh_hash_table
Definition: detect.h:762
struct DetectBufferType_ DetectBufferType
struct DetectEngineCtx_ * next
Definition: detect.h:859
struct SCProfilePrefilterData_ * prefilter_perf_data
Definition: detect.h:1123
DetectMpmAppLayerRegistery * app_mpms_list
Definition: detect.h:889
struct SCSigOrderFunc_ * sc_sig_order_funcs
Definition: detect.h:749
uint32_t content_limit
Definition: detect.h:836
PrefilterRuleStore pmq
Definition: detect.h:1064
struct DetectEngineThreadCtx_ DetectEngineThreadCtx
struct RuleMatchCandidateTx RuleMatchCandidateTx
const struct DetectFilestoreData_ * filestore_ctx
Definition: detect.h:550
Signature * DetectGetTagSignature(void)
uint32_t profile_match_logging_threshold
Definition: detect.h:848
SigFileLoaderStat sig_stat
Definition: detect.h:904
threshold ctx
Definition: detect.h:674
uint8_t * found
Definition: detect.h:605
uint16_t counter_match_list
Definition: detect.h:1007
uint16_t alternative
Definition: detect.h:1161
uint16_t addr_dst_match6_cnt
Definition: detect.h:520
AppLayerDecoderEvents * DetectEngineGetEvents(DetectEngineThreadCtx *det_ctx)
uint32_t buffer_type_map_elements
Definition: detect.h:879
struct DetectEngineThreadKeywordCtxItem_ * next
Definition: detect.h:703
struct DetectMpmAppLayerRegistery_::@93 v2
Address ip2
Definition: detect.h:145
HashTable * mt_det_ctxs_hash
Definition: detect.h:981
PrefilterEngineList * payload_engines
Definition: detect.h:1290
SigIntId match_array_cnt
Definition: detect.h:1050
DetectEngineAppInspectionEngine * app_inspect_engines
Definition: detect.h:888
AppProto alproto
Definition: detect.h:499
struct SigMatch_ ** smlists_tail
Definition: detect.h:491
DetectAddress * ipv4_head
Definition: detect.h:158
DetectEngineTenantMapping * tenant_mapping_list
Definition: detect.h:1396
PrefilterEngine * payload_engines
Definition: detect.h:1319
uint32_t prefilter_id
Definition: detect.h:892
struct SCProfilePrefilterDetectCtx_ * profile_prefilter_ctx
Definition: detect.h:845
uint16_t max_uniq_toclient_groups
Definition: detect.h:781
HashTable * reference_conf_ht
Definition: detect.h:754
uint32_t flags
Definition: detect.h:1299
uint32_t ref_cnt
Definition: detect.h:857
uint32_t a_src_uniq24
Definition: detect.h:647
struct Signature_ * next
Definition: detect.h:566
PrefilterEngineList * pkt_engines
Definition: detect.h:1289
HashTable * metadata_table
Definition: detect.h:876
uint8_t negated
Definition: detect.h:304
struct SigFileLoaderStat_ SigFileLoaderStat
Signature loader statistics.
uint32_t gid
Definition: detect.h:529
uint8_t type
Definition: detect.h:323
uint8_t * decompressed_buffer
Definition: detect.h:932
uint32_t stream_reset
Definition: detect.h:956
InspectEngineFuncPtr Callback
Definition: detect.h:413
uint32_t a_src_uniq16
Definition: detect.h:645
DetectEngineIPOnlyCtx io_ctx
Definition: detect.h:769
struct DetectReplaceList_ DetectReplaceList
int32_t sgh_mpm_context_proto_udp_packet
Definition: detect.h:809
const char * desc
Definition: detect.h:1165
uint32_t gh_unique
Definition: detect.h:759
struct SigMatch_ ** smlists
Definition: detect.h:489
HashListTable * dup_sig_hash_table
Definition: detect.h:767
uint32_t sgh_array_size
Definition: detect.h:806
char * class_msg
Definition: detect.h:555
uint32_t version
Definition: detect.h:817
uint32_t decompressed_buffer_len
Definition: detect.h:935
uint8_t * buf
Definition: detect.h:351
uint32_t smlists_array_size
Definition: detect.h:487
enum DetectEnginePrefilterSetting prefilter_setting
Definition: detect.h:865
SigMatchCtx * ctx
Definition: detect.h:325
struct DetectEngineThreadKeywordCtxItem_ DetectEngineThreadKeywordCtxItem
uint32_t len
Definition: detect.h:352
struct DetectEngineIPOnlyThreadCtx_ DetectEngineIPOnlyThreadCtx
const char * alias
Definition: detect.h:1164
IP only rules matching ctx.
Definition: detect.h:632
char * sig_error
Definition: detect.h:685
DetectEngineCtx * de_ctx
Definition: detect.h:1089
uint8_t flags
Definition: detect.h:200
TmEcode Detect(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQueue *postpq)
Detection engine thread wrapper.
Definition: detect.c:1675
uint32_t direction
Definition: detect.h:1284
uint32_t gid
Definition: detect.h:1273
DetectEngineType
Definition: detect.h:714
const SigGroupHead * SigMatchSignaturesGetSgh(const DetectEngineCtx *de_ctx, const Packet *p)
Get the SigGroupHead for a packet.
Definition: detect.c:177
struct IPOnlyCIDRItem_ * next
Definition: detect.h:310
uint16_t counter_nonmpm_list
Definition: detect.h:1005
DetectBufferType ** buffer_type_map
Definition: detect.h:878
uint64_t raw_stream_progress
Definition: detect.h:990
uint8_t type
Definition: detect.h:332
char * sig_str
Definition: detect.h:561
const DetectMpmAppLayerRegistery * reg
Definition: detect.h:599
void SigRegisterTests(void)
Definition: detect.c:5323
uint32_t idx
Definition: detect.h:616
struct SCProfileKeywordDetectCtx_ * profile_keyword_ctx
Definition: detect.h:844
struct SigGroupHead_ ** sgh_array
Definition: detect.h:804
DetectPort * sp
Definition: detect.h:534
InspectEngineFuncPtr2 Callback
Definition: detect.h:417
struct SigGroupHead_ SigGroupHead
Container for matching data for a signature group.
uint16_t addr_dst_match4_cnt
Definition: detect.h:518
#define TAILQ_ENTRY(type)
Definition: queue.h:330
MpmCtx * mpm_ctx
Definition: detect.h:1220
uint16_t port
Definition: detect.h:197
uint16_t tx_id
Structure holding the signature ordering function used by the signature ordering module.
DetectEngineTransforms transforms
Definition: detect.h:588
uint32_t pcre_match_start_offset
Definition: detect.h:996
uint32_t init_flags
Definition: detect.h:459
struct SCProfileKeywordDetectCtx_ ** profile_keyword_ctx_per_list
Definition: detect.h:846
MpmThreadCtx mtcu
Definition: detect.h:1062
DetectEngineThreadKeywordCtxItem * keyword_list
Definition: detect.h:1401
int hsbd_buffer_limit
Definition: detect.h:800
AppProto alproto
Definition: detect.h:1228
struct PrefilterEngineList_ PrefilterEngineList
SRepCIDRTree * srepCIDR_ctx
Definition: detect.h:736
const char * name
Definition: detect.h:1247
DetectEngineAppInspectionEngine * app_inspect
Definition: detect.h:543
ThresholdCtx ths_ctx
Definition: detect.h:770
int failure_fatal
Definition: detect.h:725
void DetectMetadataHashFree(DetectEngineCtx *de_ctx)
struct DetectPort_ * next
Definition: detect.h:210
SigIntId signum
Definition: detect.h:307
uint32_t a_dst_uniq24
Definition: detect.h:648
const char * url
Definition: detect.h:1166
HashListTable * ht16_src
Definition: detect.h:634
struct DetectContentData_ * cd
Definition: detect.h:604
int line
Definition: detect.h:686
structure for storing potential rule matches
uint8_t family
Definition: detect.h:300
HashListTable * prefilter_hash_table
Definition: detect.h:893
uint32_t rev
Definition: detect.h:530
struct DetectEngineIPOnlyCtx_ DetectEngineIPOnlyCtx
IP only rules matching ctx.
uint8_t * buffer
Definition: detect.h:621
uint8_t * base64_decoded
Definition: detect.h:1097
uint32_t tenant_id
Definition: detect.h:968
DetectThresholdEntry ** th_entry
Definition: detect.h:678
struct SCProfileKeywordData_ ** keyword_perf_data_per_list
Definition: detect.h:1119
struct SigMatchData_ SigMatchData
Data needed for Match()
uint32_t prefilter_maxid
Definition: detect.h:850
Signature ** match_array
Definition: detect.h:1045
struct PrefilterEngineList_ * next
Definition: detect.h:1242
SignatureMask mask
Definition: detect.h:943
Signature reference list.
int inspection_recursion_counter
Definition: detect.h:1041
uint16_t idx
Definition: detect.h:324
SignatureNonPrefilterStore * non_pf_store_ptr
Definition: detect.h:1055
uint32_t inspect_len
Definition: detect.h:348
uint32_t sig_init_size
Definition: detect.h:653
uint32_t th_size
Definition: detect.h:679
void DetectSignatureApplyActions(Packet *p, const Signature *s, const uint8_t)
Apply action(s) and Set &#39;drop&#39; sig info, if applicable.
Definition: detect.c:1591
struct SCProfileDetectCtx_ * profile_ctx
Definition: detect.h:843
uint8_t sgh_mpm_context
Definition: detect.h:785
const uint8_t * inspect
Definition: detect.h:347
struct DetectMpmAppLayerKeyword_ DetectMpmAppLayerKeyword
structure for storing per detect engine mpm keyword settings
uint32_t * flags
Definition: detect.h:950
DetectEngineIPOnlyThreadCtx io_ctx
Definition: detect.h:1071
void RuleMatchCandidateTxArrayFree(DetectEngineThreadCtx *det_ctx)
Definition: detect.c:1052
char * sig_str
Definition: detect.h:684
uint32_t a_dst_uniq16
Definition: detect.h:646
int tx_min_progress
Definition: detect.h:1259
uint8_t stream_result
Definition: detect.h:954
struct SignatureNonPrefilterStore_ SignatureNonPrefilterStore
bool supports_transforms
Definition: detect.h:434
SignatureNonPrefilterStore * non_pf_other_store_array
Definition: detect.h:1308
void(* Free)(void *pectx)
Definition: detect.h:1245
struct SigGroupHeadInitData_ SigGroupHeadInitData
DetectEngineCtx * list
Definition: detect.h:1385
Per thread variable structure.
Definition: threadvars.h:57
SignatureMask mask
Definition: detect.h:504
struct SigMatchCtx_ SigMatchCtx
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
uint16_t counter_mpm_list
Definition: detect.h:1004
uint8_t file_flags
Definition: detect.h:509
InspectionBufferMultipleForList * buffers
Definition: detect.h:1022
uint16_t port2
Definition: detect.h:198
uint32_t app_mpms_list_cnt
Definition: detect.h:890
uint32_t sig_cnt
Definition: detect.h:730
uint32_t non_pf_id_cnt
Definition: detect.h:977
void ** global_keyword_ctxs_array
Definition: detect.h:1095
struct DetectReplaceList_ * next
Definition: detect.h:606
uint16_t dsize_low
Definition: detect.h:501
uint16_t flags
Definition: detect.h:1157
Structure for the radix tree.
SpmThreadCtx * spm_thread_ctx
Definition: detect.h:1068
InspectionBuffer *(* InspectionBufferGetDataPtr)(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Flow *f, const uint8_t flow_flags, void *txv, const int list_id)
Definition: detect.h:378
AppLayerDecoderEvents * decoder_events
Definition: detect.h:1101
AppProto alproto
Definition: detect.h:1256
SigMatch * mpm_sm
Definition: detect.h:466
const DetectAddressHead * src
Definition: detect.h:483
HashListTable * dport_hash_table
Definition: detect.h:867
uint8_t * sig_array
Definition: detect.h:1280
#define FLOW_STATES
Definition: detect.h:671
Flow data structure.
Definition: flow.h:325
uint32_t base64_decode_max_len
Definition: detect.h:824
uint32_t mt_det_ctxs_cnt
Definition: detect.h:979
#define SigIntId
DetectAddress * ipv6_head
Definition: detect.h:159
DetectSigmatchListEnum
Definition: detect.h:91
Port structure for detection engine.
Definition: detect.h:196
uint32_t buffers_size
Definition: detect.h:1014
uint64_t offset
Definition: detect.h:936
a single match condition for a signature
Definition: detect.h:322
const DetectEngineTransforms * transforms
Definition: detect.h:419
SigMatchCtx * ctx
Definition: detect.h:334
int inspection_recursion_limit
Definition: detect.h:795
struct SigTableElmt_ SigTableElmt
element in sigmatch type table.
struct ThresholdCtx_ ThresholdCtx
threshold ctx
SigGroupHeadInitData * init
Definition: detect.h:1326