suricata
detect-engine-sigorder.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2024 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Anoop Saldanha <anoopsaldanha@gmail.com>
22  *
23  * Signature ordering part of the detection engine.
24  */
25 
26 #include "suricata-common.h"
27 #include "detect.h"
28 #include "detect-xbits.h"
29 #include "detect-flowbits.h"
30 #include "detect-flowint.h"
31 #include "detect-parse.h"
32 #include "detect-engine-sigorder.h"
33 #include "detect-pcre.h"
34 #include "detect-engine-build.h"
35 
36 #include "util-unittest.h"
37 #include "util-unittest-helper.h"
38 #include "util-debug.h"
39 #include "util-action.h"
40 #include "action-globals.h"
41 #include "flow-util.h"
42 #include "util-validate.h"
43 
44 #define DETECT_FLOWVAR_NOT_USED 1
45 #define DETECT_FLOWVAR_TYPE_READ 2
46 #define DETECT_FLOWVAR_TYPE_SET_READ 3
47 #define DETECT_FLOWVAR_TYPE_SET 4
48 
49 #define DETECT_PKTVAR_NOT_USED 1
50 #define DETECT_PKTVAR_TYPE_READ 2
51 #define DETECT_PKTVAR_TYPE_SET_READ 3
52 #define DETECT_PKTVAR_TYPE_SET 4
53 
54 #define DETECT_FLOWBITS_NOT_USED 1
55 #define DETECT_FLOWBITS_TYPE_READ 2
56 #define DETECT_FLOWBITS_TYPE_SET_READ 3
57 #define DETECT_FLOWBITS_TYPE_SET 4
58 
59 #define DETECT_FLOWINT_NOT_USED 1
60 #define DETECT_FLOWINT_TYPE_READ 2
61 #define DETECT_FLOWINT_TYPE_SET_READ 3
62 #define DETECT_FLOWINT_TYPE_SET 4
63 
64 #define DETECT_XBITS_NOT_USED 1
65 #define DETECT_XBITS_TYPE_READ 2
66 #define DETECT_XBITS_TYPE_SET_READ 3
67 #define DETECT_XBITS_TYPE_SET 4
68 
69 /**
70  * \brief Different kinds of helper data that can be used by the signature
71  * ordering module. Used by the "user" field in SCSigSignatureWrapper
72  */
73 typedef enum {
82 
83 /**
84  * \brief Signature wrapper used by signature ordering module while ordering
85  * signatures
86  */
87 typedef struct SCSigSignatureWrapper_ {
88  /* the wrapped signature */
90 
91  /* user data that is to be associated with this sigwrapper */
93 
96 
97 /**
98  * \brief Structure holding the signature ordering function used by the
99  * signature ordering module
100  */
101 typedef struct SCSigOrderFunc_ {
102  /* Pointer to the Signature Ordering function */
104 
107 
108 /**
109  * \brief Registers a keyword-based, signature ordering function
110  *
111  * \param de_ctx Pointer to the detection engine context from which the
112  * signatures have to be ordered.
113  * \param FuncPtr Pointer to the signature ordering function. The prototype of
114  * the signature ordering function should accept a pointer to a
115  * SCSigSignatureWrapper as its argument and shouldn't return
116  * anything
117  */
118 static void SCSigRegisterSignatureOrderingFunc(DetectEngineCtx *de_ctx,
120 {
121  SCSigOrderFunc *curr = NULL;
122  SCSigOrderFunc *prev = NULL;
123  SCSigOrderFunc *temp = NULL;
124 
125  curr = de_ctx->sc_sig_order_funcs;
126 
127  /* Walk to the end of the list, and leave prev pointing at the
128  last element. */
129  prev = curr;
130  while (curr != NULL) {
131  if (curr->SWCompare == SWCompare) {
132  /* Already specified this compare */
133  return;
134  }
135  prev = curr;
136  curr = curr->next;
137  }
138 
139  if ((temp = SCCalloc(1, sizeof(SCSigOrderFunc))) == NULL) {
140  FatalError("Fatal error encountered in SCSigRegisterSignatureOrderingFunc. Exiting...");
141  }
142 
143  temp->SWCompare = SWCompare;
144 
145  /* Append the new compare function at the end of the list. */
146  if (prev == NULL)
147  de_ctx->sc_sig_order_funcs = temp;
148  else
149  prev->next = temp;
150 }
151 
152 /**
153  * \brief Returns the flowbit type set for this signature. If more than one
154  * flowbit has been set for the same rule, we return the flowbit type of
155  * the maximum priority/value, where priority/value is maximum for the
156  * ones that set the value and the lowest for ones that read the value.
157  * If no flowbit has been set for the rule, we return 0, which indicates
158  * the least value amongst flowbit types.
159  *
160  * \param sig Pointer to the Signature from which the flowbit value has to be
161  * returned.
162  *
163  * \retval flowbits The flowbits type for this signature if it is set; if it is
164  * not set, return 0
165  */
166 static inline int SCSigGetFlowbitsType(Signature *sig)
167 {
168  DetectFlowbitsData *fb = NULL;
169  int flowbits_user_type = DETECT_FLOWBITS_NOT_USED;
170  int read = 0;
171  int write = 0;
173 
174  while (sm != NULL) {
175  if (sm->type == DETECT_FLOWBITS) {
176  fb = (DetectFlowbitsData *)sm->ctx;
177  if (fb->cmd == DETECT_FLOWBITS_CMD_ISNOTSET ||
179  read++;
180  } else {
181 #ifdef DEBUG
182  BUG_ON(1);
183 #endif
184  }
185  }
186 
187  sm = sm->next;
188  }
189 
191  while (sm != NULL) {
192  if (sm->type == DETECT_FLOWBITS) {
193  fb = (DetectFlowbitsData *)sm->ctx;
195  write++;
196  } else {
197 #ifdef DEBUG
198  BUG_ON(1);
199 #endif
200  }
201  }
202 
203  sm = sm->next;
204  }
205 
206  if (read > 0 && write == 0) {
207  flowbits_user_type = DETECT_FLOWBITS_TYPE_READ;
208  } else if (read == 0 && write > 0) {
209  flowbits_user_type = DETECT_FLOWBITS_TYPE_SET;
210  } else if (read > 0 && write > 0) {
211  flowbits_user_type = DETECT_FLOWBITS_TYPE_SET_READ;
212  }
213 
214  SCLogDebug("Sig %s typeval %d", sig->msg, flowbits_user_type);
215 
216  return flowbits_user_type;
217 }
218 
219 static inline int SCSigGetFlowintType(Signature *sig)
220 {
221  DetectFlowintData *fi = NULL;
222  int flowint_user_type = DETECT_FLOWINT_NOT_USED;
223  int read = 0;
224  int write = 0;
226 
227  while (sm != NULL) {
228  if (sm->type == DETECT_FLOWINT) {
229  fi = (DetectFlowintData *)sm->ctx;
235  read++;
236  } else {
237 #ifdef DEBUG
238  BUG_ON(1);
239 #endif
240  }
241  }
242 
243  sm = sm->next;
244  }
245 
247  while (sm != NULL) {
248  if (sm->type == DETECT_FLOWINT) {
249  fi = (DetectFlowintData *)sm->ctx;
250  if (fi->modifier == FLOWINT_MODIFIER_SET ||
253  write++;
254  } else {
255 #ifdef DEBUG
256  BUG_ON(1);
257 #endif
258  }
259  }
260 
261  sm = sm->next;
262  }
263 
264  if (read > 0 && write == 0) {
265  flowint_user_type = DETECT_FLOWINT_TYPE_READ;
266  } else if (read == 0 && write > 0) {
267  flowint_user_type = DETECT_FLOWINT_TYPE_SET;
268  } else if (read > 0 && write > 0) {
269  flowint_user_type = DETECT_FLOWINT_TYPE_SET_READ;
270  }
271 
272  SCLogDebug("Sig %s typeval %d", sig->msg, flowint_user_type);
273 
274  return flowint_user_type;
275 }
276 
277 /**
278  * \brief Returns whether the flowvar set for this rule, sets the flowvar or
279  * reads the flowvar. If the rule sets the flowvar the function returns
280  * DETECT_FLOWVAR_TYPE_SET(3), if it reads the flowvar the function
281  * returns DETECT_FLOWVAR_TYPE_READ(2), and if flowvar is not used in this
282  * rule the function returns DETECT_FLOWVAR_NOT_USED(1)
283  *
284  * \param sig Pointer to the Signature from which the flowvar type has to be
285  * returned.
286  *
287  * \retval type DETECT_FLOWVAR_TYPE_SET(3) if the rule sets the flowvar,
288  * DETECT_FLOWVAR_TYPE_READ(2) if it reads, and
289  * DETECT_FLOWVAR_NOT_USED(1) if flowvar is not used.
290  */
291 static inline int SCSigGetFlowvarType(Signature *sig)
292 {
293  DetectPcreData *pd = NULL;
295  int read = 0;
296  int write = 0;
298 
299  while (sm != NULL) {
300  pd = (DetectPcreData *)sm->ctx;
301  if (sm->type == DETECT_PCRE) {
302  uint8_t x;
303  for (x = 0; x < pd->idx; x++) {
304  if (pd->captypes[x] == VAR_TYPE_FLOW_VAR) {
305  write++;
306  break;
307  }
308  }
309  }
310 
311  sm = sm->next;
312  }
313 
315  pd = NULL;
316  while (sm != NULL) {
317  if (sm->type == DETECT_FLOWVAR) {
318  read++;
319  }
320 
321  sm = sm->next;
322  }
323 
324  if (read > 0 && write == 0) {
326  } else if (read == 0 && write > 0) {
328  } else if (read > 0 && write > 0) {
330  }
331 
332  return type;
333 }
334 
335 /**
336  * \brief Returns whether the pktvar set for this rule, sets the flowvar or
337  * reads the pktvar. If the rule sets the pktvar the function returns
338  * DETECT_PKTVAR_TYPE_SET(3), if it reads the pktvar the function
339  * returns DETECT_PKTVAR_TYPE_READ(2), and if pktvar is not used in this
340  * rule the function returns DETECT_PKTVAR_NOT_USED(1)
341  *
342  * \param sig Pointer to the Signature from which the pktvar type has to be
343  * returned.
344  *
345  * \retval type DETECT_PKTVAR_TYPE_SET(3) if the rule sets the flowvar,
346  * DETECT_PKTVAR_TYPE_READ(2) if it reads, and
347  * DETECT_PKTVAR_NOT_USED(1) if pktvar is not used.
348  */
349 static inline int SCSigGetPktvarType(Signature *sig)
350 {
351  DetectPcreData *pd = NULL;
353  int read = 0;
354  int write = 0;
356 
357  while (sm != NULL) {
358  pd = (DetectPcreData *)sm->ctx;
359  if (sm->type == DETECT_PCRE) {
360  uint8_t x;
361  for (x = 0; x < pd->idx; x++) {
362  if (pd->captypes[x] == VAR_TYPE_PKT_VAR) {
363  write++;
364  break;
365  }
366  }
367  }
368 
369  sm = sm->next;
370  }
371 
373  pd = NULL;
374  while (sm != NULL) {
375  if (sm->type == DETECT_PKTVAR) {
376  read++;
377  }
378 
379  sm = sm->next;
380  }
381 
382  if (read > 0 && write == 0) {
384  } else if (read == 0 && write > 0) {
386  } else if (read > 0 && write > 0) {
388  }
389 
390  return type;
391 }
392 
393 /**
394  * \brief Returns the xbit type set for this signature. If more than one
395  * xbit has been set for the same rule, we return the xbit type of
396  * the maximum priority/value, where priority/value is maximum for the
397  * ones that set the value and the lowest for ones that read the value.
398  * If no xbit has been set for the rule, we return 0, which indicates
399  * the least value amongst xbit types.
400  *
401  * \param sig Pointer to the Signature from which the xbit value has to be
402  * returned.
403  *
404  * \retval xbits The xbits type for this signature if it is set; if it is
405  * not set, return 0
406  */
407 static inline int SCSigGetXbitsType(Signature *sig, enum VarTypes type)
408 {
409  DetectXbitsData *fb = NULL;
410  int xbits_user_type = DETECT_XBITS_NOT_USED;
411  int read = 0;
412  int write = 0;
414 
415  while (sm != NULL) {
416  if (sm->type == DETECT_XBITS) {
417  fb = (DetectXbitsData *)sm->ctx;
418  if (fb->type == type) {
419  if (fb->cmd == DETECT_XBITS_CMD_ISNOTSET ||
420  fb->cmd == DETECT_XBITS_CMD_ISSET) {
421  read++;
422  } else {
423 #ifdef DEBUG
424  BUG_ON(1);
425 #endif
426  }
427  }
428  }
429 
430  sm = sm->next;
431  }
432 
434  while (sm != NULL) {
435  if (sm->type == DETECT_HOSTBITS) {
436  fb = (DetectXbitsData *)sm->ctx;
437  if (fb->type == type) {
438  if (fb->cmd == DETECT_XBITS_CMD_SET ||
439  fb->cmd == DETECT_XBITS_CMD_UNSET ||
440  fb->cmd == DETECT_XBITS_CMD_TOGGLE) {
441  write++;
442  } else {
443 #ifdef DEBUG
444  BUG_ON(1);
445 #endif
446  }
447  }
448  }
449 
450  sm = sm->next;
451  }
452 
453  if (read > 0 && write == 0) {
454  xbits_user_type = DETECT_XBITS_TYPE_READ;
455  } else if (read == 0 && write > 0) {
456  xbits_user_type = DETECT_XBITS_TYPE_SET;
457  } else if (read > 0 && write > 0) {
458  xbits_user_type = DETECT_XBITS_TYPE_SET_READ;
459  }
460 
461  SCLogDebug("Sig %s typeval %d", sig->msg, xbits_user_type);
462 
463  return xbits_user_type;
464 }
465 
466 /**
467  * \brief Processes the flowbits data for this signature and caches it for
468  * future use. This is needed to optimize the sig_ordering module.
469  *
470  * \param sw The sigwrapper/signature for which the flowbits data has to be
471  * cached
472  */
473 static inline void SCSigProcessUserDataForFlowbits(SCSigSignatureWrapper *sw)
474 {
475  sw->user[DETECT_SIGORDER_FLOWBITS] = SCSigGetFlowbitsType(sw->sig);
476 }
477 
478 /**
479  * \brief Processes the flowvar data for this signature and caches it for
480  * future use. This is needed to optimize the sig_ordering module.
481  *
482  * \param sw The sigwrapper/signature for which the flowvar data has to be
483  * cached
484  */
485 static inline void SCSigProcessUserDataForFlowvar(SCSigSignatureWrapper *sw)
486 {
487  sw->user[DETECT_SIGORDER_FLOWVAR] = SCSigGetFlowvarType(sw->sig);
488 }
489 
490 static inline void SCSigProcessUserDataForFlowint(SCSigSignatureWrapper *sw)
491 {
492  sw->user[DETECT_SIGORDER_FLOWINT] = SCSigGetFlowintType(sw->sig);
493 }
494 
495 /**
496  * \brief Processes the pktvar data for this signature and caches it for
497  * future use. This is needed to optimize the sig_ordering module.
498  *
499  * \param sw The sigwrapper/signature for which the pktvar data has to be
500  * cached
501  */
502 static inline void SCSigProcessUserDataForPktvar(SCSigSignatureWrapper *sw)
503 {
504  sw->user[DETECT_SIGORDER_PKTVAR] = SCSigGetPktvarType(sw->sig);
505 }
506 
507 /**
508  * \brief Processes the hostbits data for this signature and caches it for
509  * future use. This is needed to optimize the sig_ordering module.
510  *
511  * \param sw The sigwrapper/signature for which the hostbits data has to be
512  * cached
513  */
514 static inline void SCSigProcessUserDataForHostbits(SCSigSignatureWrapper *sw)
515 {
516  sw->user[DETECT_SIGORDER_HOSTBITS] = SCSigGetXbitsType(sw->sig, VAR_TYPE_HOST_BIT);
517 }
518 
519 /**
520  * \brief Processes the hostbits data for this signature and caches it for
521  * future use. This is needed to optimize the sig_ordering module.
522  *
523  * \param sw The sigwrapper/signature for which the hostbits data has to be
524  * cached
525  */
526 static inline void SCSigProcessUserDataForIPPairbits(SCSigSignatureWrapper *sw)
527 {
528  sw->user[DETECT_SIGORDER_IPPAIRBITS] = SCSigGetXbitsType(sw->sig, VAR_TYPE_IPPAIR_BIT);
529 }
530 
531 /* Return 1 if sw1 comes before sw2 in the final list. */
532 static int SCSigLessThan(SCSigSignatureWrapper *sw1,
534  SCSigOrderFunc *cmp_func_list)
535 {
536  SCSigOrderFunc *funcs = cmp_func_list;
537 
538  while (funcs != NULL) {
539  int delta = funcs->SWCompare(sw1, sw2);
540  if (delta > 0)
541  return 1;
542  else if (delta < 0)
543  return 0;
544 
545  funcs = funcs->next;
546  }
547  // They are equal, so use sid as the final decider.
548  return sw1->sig->id < sw2->sig->id;
549 }
550 
551 /* Merge sort based on a list of compare functions
552  * debug asserts are here to guide scan-build */
553 static SCSigSignatureWrapper *SCSigOrder(SCSigSignatureWrapper *sw,
554  SCSigOrderFunc *cmp_func_list)
555 {
556  DEBUG_VALIDATE_BUG_ON(sw == NULL);
557 
558  SCSigSignatureWrapper *subA = NULL;
559  SCSigSignatureWrapper *subB = NULL;
560  SCSigSignatureWrapper *first;
561  SCSigSignatureWrapper *second;
562  SCSigSignatureWrapper *result = NULL;
563  SCSigSignatureWrapper *last = NULL;
564  SCSigSignatureWrapper *new = NULL;
565 
566  /* Divide input list into two sub-lists. */
567  while (sw != NULL) {
568  first = sw;
569  sw = sw->next;
570  /* Push the first element onto sub-list A */
571  first->next = subA;
572  subA = first;
573 
574  if (sw == NULL)
575  break;
576  second = sw;
577  sw = sw->next;
578  /* Push the second element onto sub-list B */
579  second->next = subB;
580  subB = second;
581  }
582  if (subB == NULL) {
583  /* Only zero or one element on the list. */
584  return subA;
585  }
586  DEBUG_VALIDATE_BUG_ON(subA == NULL);
587 
588  /* Now sort each list */
589  subA = SCSigOrder(subA, cmp_func_list);
590  subB = SCSigOrder(subB, cmp_func_list);
591  DEBUG_VALIDATE_BUG_ON(subA == NULL);
592  DEBUG_VALIDATE_BUG_ON(subB == NULL);
593 
594  /* Merge the two sorted lists. */
595  while (subA != NULL && subB != NULL) {
596  if (SCSigLessThan(subA, subB, cmp_func_list)) {
597  new = subA;
598  subA = subA->next;
599  } else {
600  new = subB;
601  subB = subB->next;
602  }
603  /* Push onto the end of the output list. */
604  new->next = NULL;
605  if (result == NULL) {
606  result = new;
607  last = new;
608  } else {
609  last->next = new;
610  last = new;
611  }
612  }
613  /* Attach the rest of any remaining list. Only one can be non-NULL here. */
614  if (subA == NULL)
615  last->next = subB;
616  else if (subB == NULL)
617  last->next = subA;
618 
619  return result;
620 }
621 
622 /**
623  * \brief Orders an incoming Signature based on its action
624  *
625  * \param de_ctx Pointer to the detection engine context from which the
626  * signatures have to be ordered.
627  * \param sw The new signature that has to be ordered based on its action
628  */
629 static int SCSigOrderByActionCompare(SCSigSignatureWrapper *sw1,
631 {
632  return ActionOrderVal(sw2->sig->action) - ActionOrderVal(sw1->sig->action);
633 }
634 
635 /**
636  * \brief Orders an incoming Signature based on its flowbits type
637  *
638  * \param de_ctx Pointer to the detection engine context from which the
639  * signatures have to be ordered.
640  * \param sw The new signature that has to be ordered based on its flowbits
641  */
642 static int SCSigOrderByFlowbitsCompare(SCSigSignatureWrapper *sw1,
644 {
646 }
647 
648 /**
649  * \brief Orders an incoming Signature based on its flowvar type
650  *
651  * \param de_ctx Pointer to the detection engine context from which the
652  * signatures have to be ordered.
653  * \param sw The new signature that has to be ordered based on its flowvar
654  */
655 static int SCSigOrderByFlowvarCompare(SCSigSignatureWrapper *sw1,
657 {
659 }
660 
661 /**
662  * \brief Orders an incoming Signature based on its pktvar type
663  *
664  * \param de_ctx Pointer to the detection engine context from which the
665  * signatures have to be ordered.
666  * \param sw The new signature that has to be ordered based on its pktvar
667  */
668 static int SCSigOrderByPktvarCompare(SCSigSignatureWrapper *sw1,
670 {
672 }
673 
674 static int SCSigOrderByFlowintCompare(SCSigSignatureWrapper *sw1,
676 {
678 }
679 
680 /**
681  * \brief Orders an incoming Signature based on its hostbits type
682  *
683  * \param de_ctx Pointer to the detection engine context from which the
684  * signatures have to be ordered.
685  * \param sw The new signature that has to be ordered based on its hostbits
686  */
687 static int SCSigOrderByHostbitsCompare(SCSigSignatureWrapper *sw1,
689 {
691 }
692 
693 /**
694  * \brief Orders an incoming Signature based on its ippairbits (xbits) type
695  *
696  * \param de_ctx Pointer to the detection engine context from which the
697  * signatures have to be ordered.
698  * \param sw The new signature that has to be ordered based on its bits
699  */
700 static int SCSigOrderByIPPairbitsCompare(SCSigSignatureWrapper *sw1,
702 {
704 }
705 
706 /**
707  * \brief Orders an incoming Signature based on its priority type
708  *
709  * \param de_ctx Pointer to the detection engine context from which the
710  * signatures have to be ordered.
711  * \param sw The new signature that has to be ordered based on its priority
712  */
713 static int SCSigOrderByPriorityCompare(SCSigSignatureWrapper *sw1,
715 {
716  if (sw1->sig->prio > sw2->sig->prio) {
717  return -1;
718  } else if (sw1->sig->prio < sw2->sig->prio) {
719  return 1;
720  }
721  return 0;
722 }
723 
724 static int SCSigOrderByIId(SCSigSignatureWrapper *sw1, SCSigSignatureWrapper *sw2)
725 {
726  if (sw1->sig->iid > sw2->sig->iid) {
727  return -1;
728  } else if (sw1->sig->iid < sw2->sig->iid) {
729  return 1;
730  }
731  return 0;
732 }
733 
734 /* sort by:
735  * alproto, progress, iid
736  */
737 static int SCSigOrderByAppFirewall(SCSigSignatureWrapper *sw1, SCSigSignatureWrapper *sw2)
738 {
739  int sw1dir = (sw1->sig->flags & SIG_FLAG_TOSERVER) != 0 ? 0 : 1;
740  int sw2dir = (sw2->sig->flags & SIG_FLAG_TOSERVER) != 0 ? 0 : 1;
741 
742  if (sw1dir > sw2dir) {
743  return -1;
744  } else if (sw1dir < sw2dir) {
745  return 1;
746  }
747 
748  if (sw1->sig->alproto > sw2->sig->alproto) {
749  return -1;
750  } else if (sw1->sig->alproto < sw2->sig->alproto) {
751  return 1;
752  }
753 
754  if (sw1->sig->app_progress_hook > sw2->sig->app_progress_hook) {
755  return -1;
756  } else if (sw1->sig->app_progress_hook < sw2->sig->app_progress_hook) {
757  return 1;
758  }
759 
760  if (sw1->sig->iid > sw2->sig->iid) {
761  return -1;
762  } else if (sw1->sig->iid < sw2->sig->iid) {
763  return 1;
764  }
765  return 0;
766 }
767 
768 /**
769  * \brief Creates a Wrapper around the Signature
770  *
771  * \param Pointer to the Signature to be wrapped
772  *
773  * \retval sw Pointer to the wrapper that holds the signature
774  */
775 static inline SCSigSignatureWrapper *SCSigAllocSignatureWrapper(Signature *sig)
776 {
777  SCSigSignatureWrapper *sw = NULL;
778 
779  if ((sw = SCCalloc(1, sizeof(SCSigSignatureWrapper))) == NULL)
780  return NULL;
781 
782  sw->sig = sig;
783 
784  /* Process data from the signature into a cache for further use by the
785  * sig_ordering module */
786  SCSigProcessUserDataForFlowbits(sw);
787  SCSigProcessUserDataForFlowvar(sw);
788  SCSigProcessUserDataForFlowint(sw);
789  SCSigProcessUserDataForPktvar(sw);
790  SCSigProcessUserDataForHostbits(sw);
791  SCSigProcessUserDataForIPPairbits(sw);
792 
793  return sw;
794 }
795 
796 /**
797  * \brief Orders the signatures
798  *
799  * \param de_ctx Pointer to the Detection Engine Context that holds the
800  * signatures to be ordered
801  */
803 {
804  if (de_ctx->sig_list == NULL) {
805  SCLogDebug("no signatures to order");
806  return;
807  }
808 
809  SCLogDebug("ordering signatures in memory");
810  SCSigSignatureWrapper *sigw = NULL;
811  SCSigSignatureWrapper *td_sigw_list = NULL; /* unified td list */
812 
813  SCSigSignatureWrapper *fw_pf_sigw_list = NULL; /* hook: packet_filter */
814  SCSigSignatureWrapper *fw_af_sigw_list = NULL; /* hook: app_filter */
815 
816  Signature *sig = de_ctx->sig_list;
817  while (sig != NULL) {
818  sigw = SCSigAllocSignatureWrapper(sig);
819  /* Push signature wrapper onto a list, order doesn't matter here. */
820  if (sig->init_data->firewall_rule) {
821  if (sig->type == SIG_TYPE_PKT) {
822  sigw->next = fw_pf_sigw_list;
823  fw_pf_sigw_list = sigw;
824  } else {
825  // TODO review types.
826  sigw->next = fw_af_sigw_list;
827  fw_af_sigw_list = sigw;
828  }
829  } else {
830  sigw->next = td_sigw_list;
831  td_sigw_list = sigw;
832  }
833  sig = sig->next;
834  }
835 
836  /* despite having Append in the name, the new Sig/Rule funcs actually prepend with some special
837  * logic around bidir sigs. So to respect the firewall rule order, we sort this part of the list
838  * by the add order. */
839  if (fw_pf_sigw_list) {
840  SCSigOrderFunc OrderFn = { .SWCompare = SCSigOrderByIId, .next = NULL };
841  fw_pf_sigw_list = SCSigOrder(fw_pf_sigw_list, &OrderFn);
842  }
843  if (fw_af_sigw_list) {
844  SCSigOrderFunc OrderFn = { .SWCompare = SCSigOrderByAppFirewall, .next = NULL };
845  fw_af_sigw_list = SCSigOrder(fw_af_sigw_list, &OrderFn);
846  }
847  if (td_sigw_list) {
848  /* Sort the list */
849  td_sigw_list = SCSigOrder(td_sigw_list, de_ctx->sc_sig_order_funcs);
850  }
851  /* Recreate the sig list in order */
852  de_ctx->sig_list = NULL;
853 
854  /* firewall list for hook packet_filter */
855  for (sigw = fw_pf_sigw_list; sigw != NULL;) {
856  SCLogDebug("post-sort packet_filter: sid %u", sigw->sig->id);
857  sigw->sig->next = NULL;
858  if (de_ctx->sig_list == NULL) {
859  /* First entry on the list */
860  de_ctx->sig_list = sigw->sig;
861  sig = de_ctx->sig_list;
862  } else {
863  sig->next = sigw->sig;
864  sig = sig->next;
865  }
866 
867  SCSigSignatureWrapper *sigw_to_free = sigw;
868  sigw = sigw->next;
869  SCFree(sigw_to_free);
870  }
871  /* firewall list for hook app_filter */
872  for (sigw = fw_af_sigw_list; sigw != NULL;) {
873  SCLogDebug("post-sort app_filter: sid %u", sigw->sig->id);
874  sigw->sig->next = NULL;
875  if (de_ctx->sig_list == NULL) {
876  /* First entry on the list */
877  de_ctx->sig_list = sigw->sig;
878  sig = de_ctx->sig_list;
879  } else {
880  sig->next = sigw->sig;
881  sig = sig->next;
882  }
883 
884  SCSigSignatureWrapper *sigw_to_free = sigw;
885  sigw = sigw->next;
886  SCFree(sigw_to_free);
887  }
888  /* threat detect list for hook app_td */
889  for (sigw = td_sigw_list; sigw != NULL;) {
890  sigw->sig->next = NULL;
891  if (de_ctx->sig_list == NULL) {
892  /* First entry on the list */
893  de_ctx->sig_list = sigw->sig;
894  sig = de_ctx->sig_list;
895  } else {
896  sig->next = sigw->sig;
897  sig = sig->next;
898  }
899 
900  SCSigSignatureWrapper *sigw_to_free = sigw;
901  sigw = sigw->next;
902  SCFree(sigw_to_free);
903  }
904 }
905 
906 /**
907  * \brief Lets you register the Signature ordering functions. The order in
908  * which the functions are registered shows the priority. The first
909  * function registered provides more priority than the function
910  * registered after it. To add a new registration function, register
911  * it by listing it in the correct position in the below sequence,
912  * based on the priority you would want to offer to that keyword.
913  *
914  * \param de_ctx Pointer to the detection engine context from which the
915  * signatures have to be ordered.
916  */
918 {
919  SCLogDebug("registering signature ordering functions");
920 
921  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
922  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowbitsCompare);
923  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowintCompare);
924  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowvarCompare);
925  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPktvarCompare);
926  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByHostbitsCompare);
927  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByIPPairbitsCompare);
928  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPriorityCompare);
929 }
930 
931 /**
932  * \brief De-registers all the signature ordering functions registered
933  *
934  * \param de_ctx Pointer to the detection engine context from which the
935  * signatures were ordered.
936  */
938 {
939  SCSigOrderFunc *funcs;
940  void *temp;
941 
942  /* clean the memory alloted to the signature ordering funcs */
943  funcs = de_ctx->sc_sig_order_funcs;
944  while (funcs != NULL) {
945  temp = funcs;
946  funcs = funcs->next;
947  SCFree(temp);
948  }
949  de_ctx->sc_sig_order_funcs = NULL;
950 }
951 
952 /**********Unittests**********/
953 
958 
959 #ifdef UNITTESTS
960 
961 static int SCSigOrderingTest01(void)
962 {
963  SCSigOrderFunc *temp = NULL;
964  int i = 0;
965 
968 
969  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
970  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
971  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
972  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
973  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
974  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPriorityCompare);
975  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowbitsCompare);
976  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowbitsCompare);
977  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowvarCompare);
978  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPktvarCompare);
979  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowvarCompare);
980 
981  temp = de_ctx->sc_sig_order_funcs;
982  while (temp != NULL) {
983  i++;
984  temp = temp->next;
985  }
986 
988 
989  FAIL_IF_NOT(i == 5);
990 
991  PASS;
992 }
993 
994 static int SCSigOrderingTest02(void)
995 {
996  Signature *sig = NULL;
997 
999  FAIL_IF(de_ctx == NULL);
1000 
1002  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; offset:0; depth:4; pcre:\"/220[- ]/\"; rev:4; sid:1;)");
1003  FAIL_IF_NULL(sig);
1004 
1006  "drop tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; offset:0; depth:4; pcre:\"/220[- ]/\"; rev:4; sid:2;)");
1007  FAIL_IF_NULL(sig);
1008 
1010  "drop tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; offset:10; depth:4; pcre:\"/220[- ]/\"; rev:4; sid:3;)");
1011  FAIL_IF_NULL(sig);
1012 
1014  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; offset:0; depth:4; pcre:\"/220[- ]/\"; flowvar:http_host,\"www.oisf.net\"; rev:4; priority:1; sid:4;)");
1015  FAIL_IF_NULL(sig);
1016 
1018  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; offset:0; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:1; sid:5;)");
1019  FAIL_IF_NULL(sig);
1020 
1022  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering\"; pcre:\"/^User-Agent: (?P<flow_http_host>.*)\\r\\n/m\"; content:\"220\"; offset:10; depth:4; rev:4; priority:3; sid:6;)");
1023  FAIL_IF_NULL(sig);
1024 
1026  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; offset:10; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:3; sid:7;)");
1027  FAIL_IF_NULL(sig);
1028 
1030  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; offset:10; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:2; sid:8;)");
1031  FAIL_IF_NULL(sig);
1032 
1034  "drop tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; offset:10; depth:4; pcre:\"/^User-Agent: (?P<pkt_http_host>.*)\\r\\n/m\"; rev:4; priority:3; flowbits:set,TEST.one; flowbits:noalert; sid:9;)");
1035  FAIL_IF_NULL(sig);
1036 
1038  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:3; sid:10;)");
1039  FAIL_IF_NULL(sig);
1040 
1042  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; sid:11;)");
1043  FAIL_IF_NULL(sig);
1044 
1046  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; sid:12;)");
1047  FAIL_IF_NULL(sig);
1048 
1050  "drop tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; offset:12; depth:4; pcre:\"/220[- ]/\"; rev:4; pktvar:http_host,\"www.oisf.net\"; priority:2; flowbits:isnotset,TEST.two; sid:13;)");
1051  FAIL_IF_NULL(sig);
1052 
1054  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; offset:12; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:2; flowbits:set,TEST.two; sid:14;)");
1055  FAIL_IF_NULL(sig);
1056 
1057  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
1058  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowbitsCompare);
1059  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowvarCompare);
1060  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPktvarCompare);
1061  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPriorityCompare);
1063 
1064  sig = de_ctx->sig_list;
1065 
1066 #ifdef DEBUG
1067  while (sig != NULL) {
1068  printf("sid: %d\n", sig->id);
1069  sig = sig->next;
1070  }
1071 #endif
1072 
1073  sig = de_ctx->sig_list;
1074 
1075  /* pass */
1076  FAIL_IF_NOT(sig->id == 6);
1077  sig = sig->next;
1078  FAIL_IF_NOT(sig->id == 4);
1079  sig = sig->next;
1080  FAIL_IF_NOT(sig->id == 8);
1081  sig = sig->next;
1082  FAIL_IF_NOT(sig->id == 7);
1083  sig = sig->next;
1084  FAIL_IF_NOT(sig->id == 10);
1085  sig = sig->next;
1086 
1087  /* drops */
1088  FAIL_IF_NOT(sig->id == 9);
1089  sig = sig->next;
1090  FAIL_IF_NOT(sig->id == 13);
1091  sig = sig->next;
1092  FAIL_IF_NOT(sig->id == 2);
1093  sig = sig->next;
1094  FAIL_IF_NOT(sig->id == 3);
1095  sig = sig->next;
1096 
1097  /* alerts */
1098  FAIL_IF_NOT(sig->id == 14);
1099  sig = sig->next;
1100  FAIL_IF_NOT(sig->id == 5);
1101  sig = sig->next;
1102  FAIL_IF_NOT(sig->id == 1);
1103  sig = sig->next;
1104  FAIL_IF_NOT(sig->id == 11);
1105  sig = sig->next;
1106  FAIL_IF_NOT(sig->id == 12);
1107  sig = sig->next;
1108 
1110  PASS;
1111 }
1112 
1113 static int SCSigOrderingTest03(void)
1114 {
1115  Signature *sig = NULL;
1116 
1119 
1121  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1122  "offset:0; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:3; sid:1;)");
1123  FAIL_IF_NULL(sig);
1124 
1126  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1127  "offset:0; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:2; sid:2;)");
1128  FAIL_IF_NULL(sig);
1129 
1131  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1132  "offset:10; depth:4; pcre:\"/^User-Agent: (?P<flow_http_host>.*)\\r\\n/m\"; "
1133  "flowbits:unset,TEST.one; rev:4; priority:2; sid:3;)");
1134  FAIL_IF_NULL(sig);
1135 
1137  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1138  "offset:0; depth:4; pcre:\"/^User-Agent: (?P<pkt_http_host>.*)\\r\\n/m\"; "
1139  "flowbits:isset,TEST.one; rev:4; priority:1; sid:4;)");
1140  FAIL_IF_NULL(sig);
1141 
1143  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1144  "content:\"220\"; offset:0; depth:4; pcre:\"/220[- ]/\"; priority:2; sid:5;)");
1145  FAIL_IF_NULL(sig);
1146 
1148  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1149  "content:\"220\"; offset:10; flowbits:isnotset,TEST.one; pcre:\"/^User-Agent: "
1150  "(?P<flow_http_host>.*)\\r\\n/m\"; rev:4; sid:6;)");
1151  FAIL_IF_NULL(sig);
1152 
1154  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1155  "content:\"220\"; offset:10; depth:4; pcre:\"/220[- ]/\"; "
1156  "flowbits:unset,TEST.one; rev:4; priority:3; sid:7;)");
1157  FAIL_IF_NULL(sig);
1158 
1160  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1161  "offset:10; depth:4; pcre:\"/220[- ]/\"; flowbits:unset,TEST.one; rev:4; priority:1; "
1162  "pktvar:http_host,\"www.oisf.net\"; sid:8;)");
1163  FAIL_IF_NULL(sig);
1164 
1166  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1167  "content:\"220\"; offset:10; depth:4; rev:4; flowbits:set,TEST.one; "
1168  "flowbits:noalert; pktvar:http_host,\"www.oisf.net\"; sid:9;)");
1169  FAIL_IF_NULL(sig);
1170 
1172  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1173  "offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:3; sid:10;)");
1174  FAIL_IF_NULL(sig);
1175 
1177  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1178  "content:\"220\"; offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; sid:11;)");
1179  FAIL_IF_NULL(sig);
1180 
1182  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1183  "content:\"220\"; offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; sid:12;)");
1184  FAIL_IF_NULL(sig);
1185 
1187  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1188  "offset:12; depth:4; pcre:\"/220[- ]/\"; rev:4; flowbits:isnotset,TEST.one; sid:13;)");
1189  FAIL_IF_NULL(sig);
1190 
1192  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1193  "offset:12; depth:4; pcre:\"/220[- ]/\"; rev:4; flowbits:set,TEST.one; sid:14;)");
1194  FAIL_IF_NULL(sig);
1195 
1196  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
1197  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowbitsCompare);
1198  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowvarCompare);
1199  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPktvarCompare);
1200  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPriorityCompare);
1202 
1203  sig = de_ctx->sig_list;
1204 
1205 #ifdef DEBUG
1206  while (sig != NULL) {
1207  printf("sid: %d\n", sig->id);
1208  sig = sig->next;
1209  }
1210 #endif
1211 
1212  sig = de_ctx->sig_list;
1213 
1214  FAIL_IF_NOT(sig->id == 3);
1215  sig = sig->next;
1216 
1217  FAIL_IF_NOT(sig->id == 8);
1218  sig = sig->next;
1219  FAIL_IF_NOT(sig->id == 9);
1220  sig = sig->next;
1221  FAIL_IF_NOT(sig->id == 7);
1222  sig = sig->next;
1223  FAIL_IF_NOT(sig->id == 14);
1224  sig = sig->next;
1225  FAIL_IF_NOT(sig->id == 6);
1226  sig = sig->next;
1227  FAIL_IF_NOT(sig->id == 4);
1228  sig = sig->next;
1229  FAIL_IF_NOT(sig->id == 13);
1230  sig = sig->next;
1231  FAIL_IF_NOT(sig->id == 2);
1232  sig = sig->next;
1233  FAIL_IF_NOT(sig->id == 5);
1234  sig = sig->next;
1235  FAIL_IF_NOT(sig->id == 1);
1236  sig = sig->next;
1237  FAIL_IF_NOT(sig->id == 10);
1238  sig = sig->next;
1239  FAIL_IF_NOT(sig->id == 11);
1240  sig = sig->next;
1241  FAIL_IF_NOT(sig->id == 12);
1242 
1243  sig = sig->next;
1244 
1246 
1247  PASS;
1248 }
1249 
1250 static int SCSigOrderingTest04(void)
1251 {
1252 
1253  Signature *sig = NULL;
1254 
1256  FAIL_IF(de_ctx == NULL);
1257 
1259  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1260  "content:\"220\"; offset:0; depth:4; pcre:\"/220[- ]/\"; rev:4; sid:1;)");
1261  FAIL_IF_NULL(sig);
1262 
1264  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1265  "pcre:\"/^User-Agent: (?P<flow_http_host>.*)\\r\\n/m\"; content:\"220\"; "
1266  "offset:10; rev:4; priority:3; sid:2;)");
1267  FAIL_IF_NULL(sig);
1268 
1270  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1271  "content:\"220\"; offset:10; depth:4; pcre:\"/^User-Agent: "
1272  "(?P<flow_http_host>.*)\\r\\n/m\"; rev:4; priority:3; sid:3;)");
1273  FAIL_IF_NULL(sig);
1274 
1276  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1277  "offset:10; depth:4; pcre:\"/^User-Agent: (?P<flow_http_host>.*)\\r\\n/m\"; rev:4; "
1278  "priority:3; flowvar:http_host,\"www.oisf.net\"; sid:4;)");
1279  FAIL_IF_NULL(sig);
1280 
1282  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1283  "offset:11; depth:4; pcre:\"/^User-Agent: (?P<pkt_http_host>.*)\\r\\n/m\"; "
1284  "pcre:\"/220[- ]/\"; rev:4; priority:3; sid:5;)");
1285  FAIL_IF_NULL(sig);
1286 
1288  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1289  "offset:11; depth:4; pcre:\"/^User-Agent: (?P<pkt_http_host>.*)\\r\\n/m\"; "
1290  "pktvar:http_host,\"www.oisf.net\"; rev:4; priority:1; sid:6;)");
1291  FAIL_IF_NULL(sig);
1292 
1294  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1295  "offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; flowvar:http_host,\"www.oisf.net\"; "
1296  "pktvar:http_host,\"www.oisf.net\"; priority:1; sid:7;)");
1297  FAIL_IF_NULL(sig);
1298 
1300  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1301  "content:\"220\"; offset:12; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:2; "
1302  "flowvar:http_host,\"www.oisf.net\"; sid:8;)");
1303  FAIL_IF_NULL(sig);
1304 
1306  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1307  "content:\"220\"; offset:12; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:2; "
1308  "flowvar:http_host,\"www.oisf.net\"; sid:9;)");
1309  FAIL_IF_NULL(sig);
1310 
1311  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
1312  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowbitsCompare);
1313  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowvarCompare);
1314  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPktvarCompare);
1315  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPriorityCompare);
1317 
1318  sig = de_ctx->sig_list;
1319 
1320 #ifdef DEBUG
1321  while (sig != NULL) {
1322  printf("sid: %d\n", sig->id);
1323  sig = sig->next;
1324  }
1325 #endif
1326 
1327  sig = de_ctx->sig_list;
1328 
1329  /* flowvar set */
1330  sig = sig->next;
1331  FAIL_IF_NOT(sig->id == 3);
1332  sig = sig->next;
1333  FAIL_IF_NOT(sig->id == 4);
1334  sig = sig->next;
1335  FAIL_IF_NOT(sig->id == 7);
1336  sig = sig->next;
1337  FAIL_IF_NOT(sig->id == 8);
1338  sig = sig->next;
1339  FAIL_IF_NOT(sig->id == 9);
1340  sig = sig->next;
1341 
1342  /* pktvar */
1343 
1344  FAIL_IF_NOT(sig->id == 5);
1345  sig = sig->next;
1346  FAIL_IF_NOT(sig->id == 6);
1347  sig = sig->next;
1348 
1349  FAIL_IF_NOT(sig->id == 1);
1350  sig = sig->next;
1351 
1353 
1354  PASS;
1355 }
1356 
1357 static int SCSigOrderingTest05(void)
1358 {
1359  Signature *sig = NULL;
1360 
1362  FAIL_IF(de_ctx == NULL);
1363 
1365  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1366  "content:\"220\"; offset:0; depth:4; pcre:\"/220[- ]/\"; rev:4; sid:1;)");
1367  FAIL_IF_NULL(sig);
1368 
1370  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1371  "pcre:\"/^User-Agent: (?P<pkt_http_host>.*)\\r\\n/m\"; content:\"220\"; "
1372  "offset:10; rev:4; priority:3; sid:2;)");
1373  FAIL_IF_NULL(sig);
1374 
1376  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1377  "content:\"220\"; offset:10; depth:4; pcre:\"/^User-Agent: "
1378  "(?P<pkt_http_host>.*)\\r\\n/m\"; rev:4; priority:3; sid:3;)");
1379  FAIL_IF_NULL(sig);
1380 
1382  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1383  "offset:10; depth:4; pcre:\"/^User-Agent: (?P<pkt_http_host>.*)\\r\\n/m\"; rev:4; "
1384  "priority:3; pktvar:http_host,\"www.oisf.net\"; sid:4;)");
1385  FAIL_IF_NULL(sig);
1386 
1388  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1389  "offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:3; sid:5;)");
1390  FAIL_IF_NULL(sig);
1391 
1393  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1394  "content:\"220\"; offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; sid:6;)");
1395  FAIL_IF_NULL(sig);
1396 
1398  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1399  "content:\"220\"; offset:12; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:2; "
1400  "pktvar:http_host,\"www.oisf.net\"; sid:7;)");
1401  FAIL_IF_NULL(sig);
1402 
1404  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1405  "content:\"220\"; offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; "
1406  "pktvar:http_host,\"www.oisf.net\"; sid:8;)");
1407  FAIL_IF_NULL(sig);
1408 
1409  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
1410  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowbitsCompare);
1411  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowvarCompare);
1412  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPktvarCompare);
1413  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPriorityCompare);
1415 
1416  sig = de_ctx->sig_list;
1417 
1418  //#ifdef DEBUG
1419  while (sig != NULL) {
1420  printf("sid: %d\n", sig->id);
1421  sig = sig->next;
1422  }
1423  //#endif
1424 
1425  sig = de_ctx->sig_list;
1426 
1427  /* pktvar set */
1428  FAIL_IF_NOT(sig->id == 2);
1429  sig = sig->next;
1430  FAIL_IF_NOT(sig->id == 3);
1431  sig = sig->next;
1432  FAIL_IF_NOT(sig->id == 4);
1433  sig = sig->next;
1434  /* pktvar read */
1435  FAIL_IF_NOT(sig->id == 7);
1436  sig = sig->next;
1437  FAIL_IF_NOT(sig->id == 8);
1438  sig = sig->next;
1439  FAIL_IF_NOT(sig->id == 1);
1440  sig = sig->next;
1441  FAIL_IF_NOT(sig->id == 5);
1442  sig = sig->next;
1443  FAIL_IF_NOT(sig->id == 6);
1444  sig = sig->next;
1445 
1447 
1448  PASS;
1449 }
1450 
1451 static int SCSigOrderingTest06(void)
1452 {
1453 
1454  Signature *sig = NULL;
1455 
1458 
1460  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1461  "content:\"220\"; offset:0; depth:4; pcre:\"/220[- ]/\"; rev:4; sid:1;)");
1462  FAIL_IF_NULL(sig);
1463 
1465  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1466  "content:\"220\"; offset:10; rev:4; priority:2; sid:2;)");
1467  FAIL_IF_NULL(sig);
1468 
1470  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1471  "content:\"220\"; offset:10; depth:4; rev:4; priority:3; sid:3;)");
1472  FAIL_IF_NULL(sig);
1473 
1475  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; "
1476  "content:\"220\"; offset:10; depth:4; rev:4; priority:2; sid:4;)");
1477  FAIL_IF_NULL(sig);
1478 
1480  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1481  "offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:2; sid:5;)");
1482  FAIL_IF_NULL(sig);
1483 
1485  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1486  "offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:1; sid:6;)");
1487  FAIL_IF_NULL(sig);
1489  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1490  "offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:2; sid:7;)");
1491  FAIL_IF_NULL(sig);
1492 
1494  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering\"; content:\"220\"; "
1495  "offset:12; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:2; sid:8;)");
1496  FAIL_IF_NULL(sig);
1497 
1498  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
1499  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowbitsCompare);
1500  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowvarCompare);
1501  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPktvarCompare);
1502  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPriorityCompare);
1504 
1505  sig = de_ctx->sig_list;
1506 
1507 #ifdef DEBUG
1508  while (sig != NULL) {
1509  printf("sid: %d\n", sig->id);
1510  sig = sig->next;
1511  }
1512 #endif
1513 
1514  sig = de_ctx->sig_list;
1515 
1516  FAIL_IF_NOT(sig->id == 6);
1517  sig = sig->next;
1518  FAIL_IF_NOT(sig->id == 2);
1519  sig = sig->next;
1520  FAIL_IF_NOT(sig->id == 4);
1521  sig = sig->next;
1522  FAIL_IF_NOT(sig->id == 5);
1523  sig = sig->next;
1524  FAIL_IF_NOT(sig->id == 7);
1525  sig = sig->next;
1526  FAIL_IF_NOT(sig->id == 8);
1527  sig = sig->next;
1528  FAIL_IF_NOT(sig->id == 1);
1529  sig = sig->next;
1530  FAIL_IF_NOT(sig->id == 3);
1531  sig = sig->next;
1532 
1534 
1535  PASS;
1536 }
1537 static int SCSigOrderingTest07(void)
1538 {
1539 
1540  Signature *sig = NULL;
1541 
1543  FAIL_IF(de_ctx == NULL);
1544 
1546  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering alert\"; "
1547  "content:\"220\"; offset:0; depth:4; pcre:\"/220[- ]/\"; sid:1; rev:4;)");
1548  FAIL_IF_NULL(sig);
1549 
1551  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering pass\"; "
1552  "content:\"220\"; offset:10; sid:2; rev:4; priority:2;)");
1553  FAIL_IF_NULL(sig);
1554 
1556  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering alert\"; "
1557  "content:\"220\"; offset:10; depth:4; sid:3; rev:4; priority:3;)");
1558  FAIL_IF_NULL(sig);
1559 
1561  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering pass\"; "
1562  "content:\"220\"; offset:10; depth:4; sid:4; rev:4; priority:2;)");
1563  FAIL_IF_NULL(sig);
1564 
1566  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering pass\"; content:\"220\"; "
1567  "offset:11; depth:4; pcre:\"/220[- ]/\"; sid:5; rev:4; priority:2;)");
1568  FAIL_IF_NULL(sig);
1569 
1571  "drop tcp any !21:902 -> any any (msg:\"Testing sigordering drop\"; content:\"220\"; "
1572  "offset:11; depth:4; pcre:\"/220[- ]/\"; sid:6; rev:4; priority:1;)");
1573  FAIL_IF_NULL(sig);
1574 
1576  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering reject\"; content:\"220\"; "
1577  "offset:11; depth:4; pcre:\"/220[- ]/\"; sid:7; rev:4; priority:2;)");
1578  FAIL_IF_NULL(sig);
1579 
1581  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering alert\"; content:\"220\"; "
1582  "offset:12; depth:4; pcre:\"/220[- ]/\"; sid:8; rev:4; priority:2;)");
1583  FAIL_IF_NULL(sig);
1584 
1585  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
1586  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowbitsCompare);
1587  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowvarCompare);
1588  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPktvarCompare);
1589  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPriorityCompare);
1591 
1592  sig = de_ctx->sig_list;
1593 
1594 #ifdef DEBUG
1595  while (sig != NULL) {
1596  printf("sid: %d\n", sig->id);
1597  sig = sig->next;
1598  }
1599 #endif
1600 
1601  sig = de_ctx->sig_list;
1602 
1603  FAIL_IF_NOT(sig->id == 2);
1604  sig = sig->next;
1605  FAIL_IF_NOT(sig->id == 4);
1606  sig = sig->next;
1607  FAIL_IF_NOT(sig->id == 5);
1608  sig = sig->next;
1609  FAIL_IF_NOT(sig->id == 7);
1610  sig = sig->next;
1611  FAIL_IF_NOT(sig->id == 6);
1612  sig = sig->next;
1613  FAIL_IF_NOT(sig->id == 8);
1614  sig = sig->next;
1615  FAIL_IF_NOT(sig->id == 1);
1616  sig = sig->next;
1617  FAIL_IF_NOT(sig->id == 3);
1618  sig = sig->next;
1619 
1621 
1622  PASS;
1623 }
1624 
1625 /**
1626  * \test Order with a different Action priority
1627  * (as specified from config)
1628  */
1629 static int SCSigOrderingTest08(void)
1630 {
1631 #ifdef HAVE_LIBNET11
1632 
1633  Signature *sig = NULL;
1634  extern uint8_t action_order_sigs[4];
1635 
1636  /* Let's change the order. Default is pass, drop, reject, alert (pass has highest prio) */
1641 
1643  FAIL_IF(de_ctx == NULL);
1644 
1646  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering alert\"; "
1647  "content:\"220\"; offset:0; depth:4; pcre:\"/220[- ]/\"; sid:1; rev:4;)");
1648  FAIL_IF_NULL(sig);
1649 
1651  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering pass\"; "
1652  "content:\"220\"; offset:10; sid:2; rev:4; priority:2;)");
1653  FAIL_IF_NULL(sig);
1654 
1656  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering alert\"; "
1657  "content:\"220\"; offset:10; depth:4; sid:3; rev:4; priority:3;)");
1658  FAIL_IF_NULL(sig);
1659 
1661  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering pass\"; "
1662  "content:\"220\"; offset:10; depth:4; sid:4; rev:4; priority:2;)");
1663  FAIL_IF_NULL(sig);
1664 
1666  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering pass\"; content:\"220\"; "
1667  "offset:11; depth:4; pcre:\"/220[- ]/\"; sid:5; rev:4; priority:2;)");
1668  FAIL_IF_NULL(sig);
1669 
1671  "reject tcp any !21:902 -> any any (msg:\"Testing sigordering drop\"; content:\"220\"; "
1672  "offset:11; depth:4; pcre:\"/220[- ]/\"; sid:6; rev:4; priority:1;)");
1673  FAIL_IF_NULL(sig);
1674 
1676  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering reject\"; "
1677  "content:\"220\"; offset:11; depth:4; pcre:\"/220[- ]/\"; sid:7; rev:4;)");
1678  FAIL_IF_NULL(sig);
1679 
1681  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering alert\"; content:\"220\"; "
1682  "offset:12; depth:4; pcre:\"/220[- ]/\"; sid:8; rev:4; priority:2;)");
1683  FAIL_IF_NULL(sig);
1684 
1685  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
1686  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowbitsCompare);
1687  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowvarCompare);
1688  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPktvarCompare);
1689  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPriorityCompare);
1691 
1692  sig = de_ctx->sig_list;
1693 
1694 #ifdef DEBUG
1695  while (sig != NULL) {
1696  printf("sid: %d\n", sig->id);
1697  sig = sig->next;
1698  }
1699 #endif
1700 
1701  sig = de_ctx->sig_list;
1702 
1703  FAIL_IF_NOT(sig->id == 6);
1704  sig = sig->next;
1705  FAIL_IF_NOT(sig->id == 8);
1706  sig = sig->next;
1707  FAIL_IF_NOT(sig->id == 1);
1708  sig = sig->next;
1709  FAIL_IF_NOT(sig->id == 3);
1710  sig = sig->next;
1711  FAIL_IF_NOT(sig->id == 2);
1712  sig = sig->next;
1713  FAIL_IF_NOT(sig->id == 4);
1714  sig = sig->next;
1715  FAIL_IF_NOT(sig->id == 5);
1716  sig = sig->next;
1717  FAIL_IF_NOT(sig->id == 7);
1718  sig = sig->next;
1719 
1720  /* Restore the default pre-order definition */
1725 
1727 
1728 #endif
1729  PASS;
1730 }
1731 
1732 /**
1733  * \test Order with a different Action priority
1734  * (as specified from config)
1735  */
1736 static int SCSigOrderingTest09(void)
1737 {
1738 
1739  Signature *sig = NULL;
1740  extern uint8_t action_order_sigs[4];
1741 
1742  /* Let's change the order. Default is pass, drop, reject, alert (pass has highest prio) */
1747 
1749  FAIL_IF(de_ctx == NULL);
1750 
1752  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering alert\"; "
1753  "content:\"220\"; offset:0; depth:4; pcre:\"/220[- ]/\"; sid:1;)");
1754  FAIL_IF_NULL(sig);
1755 
1757  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering pass\"; "
1758  "content:\"220\"; offset:10; priority:2; sid:2;)");
1759  FAIL_IF_NULL(sig);
1760 
1762  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering alert\"; "
1763  "content:\"220\"; offset:10; depth:4; priority:3; sid:3;)");
1764  FAIL_IF_NULL(sig);
1765 
1767  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering pass\"; "
1768  "content:\"220\"; offset:10; depth:4; rev:4; priority:2; sid:4;)");
1769  FAIL_IF_NULL(sig);
1770 
1772  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering pass\"; content:\"220\"; "
1773  "offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:2; sid:5;)");
1774  FAIL_IF_NULL(sig);
1775 
1777  "drop tcp any !21:902 -> any any (msg:\"Testing sigordering drop\"; content:\"220\"; "
1778  "offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:1; sid:6;)");
1779  FAIL_IF_NULL(sig);
1780 
1782  "drop tcp any !21:902 -> any any (msg:\"Testing sigordering reject\"; content:\"220\"; "
1783  "offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:2; sid:7;)");
1784  FAIL_IF_NULL(sig);
1785 
1787  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering alert\"; content:\"220\"; "
1788  "offset:12; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:2; sid:8;)");
1789  FAIL_IF_NULL(sig);
1790 
1791  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
1792  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowbitsCompare);
1793  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowvarCompare);
1794  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPktvarCompare);
1795  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPriorityCompare);
1797 
1798  sig = de_ctx->sig_list;
1799 
1800 #ifdef DEBUG
1801  while (sig != NULL) {
1802  printf("sid: %d\n", sig->id);
1803  sig = sig->next;
1804  }
1805 #endif
1806 
1807  sig = de_ctx->sig_list;
1808 
1809  FAIL_IF_NOT(sig->id == 6);
1810  sig = sig->next;
1811  FAIL_IF_NOT(sig->id == 7);
1812  sig = sig->next;
1813  FAIL_IF_NOT(sig->id == 8);
1814  sig = sig->next;
1815  FAIL_IF_NOT(sig->id == 1);
1816  sig = sig->next;
1817  FAIL_IF_NOT(sig->id == 3);
1818  sig = sig->next;
1819  FAIL_IF_NOT(sig->id == 2);
1820  sig = sig->next;
1821  FAIL_IF_NOT(sig->id == 4);
1822  sig = sig->next;
1823  FAIL_IF_NOT(sig->id == 5);
1824  sig = sig->next;
1825 
1826  /* Restore the default pre-order definition */
1831 
1833  PASS;
1834 }
1835 
1836 /**
1837  * \test Order with a different Action priority
1838  * (as specified from config)
1839  */
1840 static int SCSigOrderingTest10(void)
1841 {
1842 
1843  Signature *sig = NULL;
1844  extern uint8_t action_order_sigs[4];
1845 
1846  /* Let's change the order. Default is pass, drop, reject, alert (pass has highest prio) */
1851 
1853  FAIL_IF(de_ctx == NULL);
1854 
1856  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering alert\"; "
1857  "content:\"220\"; offset:0; depth:4; pcre:\"/220[- ]/\"; rev:4; sid:1;)");
1858  FAIL_IF_NULL(sig);
1859 
1861  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering pass\"; "
1862  "content:\"220\"; offset:10; rev:4; priority:2; sid:2;)");
1863  FAIL_IF_NULL(sig);
1864 
1866  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering alert\"; "
1867  "content:\"220\"; offset:10; depth:4; rev:4; priority:3; sid:3;)");
1868  FAIL_IF_NULL(sig);
1869 
1871  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering pass\"; "
1872  "content:\"220\"; offset:10; depth:4; rev:4; priority:2; sid:4;)");
1873  FAIL_IF_NULL(sig);
1874 
1876  "pass tcp any !21:902 -> any any (msg:\"Testing sigordering pass\"; content:\"220\"; "
1877  "offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:2; sid:5;)");
1878  FAIL_IF_NULL(sig);
1879 
1881  "drop tcp any !21:902 -> any any (msg:\"Testing sigordering drop\"; content:\"220\"; "
1882  "offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:1; sid:6;)");
1883  FAIL_IF_NULL(sig);
1884 
1886  "drop tcp any !21:902 -> any any (msg:\"Testing sigordering reject\"; content:\"220\"; "
1887  "offset:11; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:2; sid:7;)");
1888  FAIL_IF_NULL(sig);
1889 
1891  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering alert\"; content:\"220\"; "
1892  "offset:12; depth:4; pcre:\"/220[- ]/\"; rev:4; priority:2; sid:8;)");
1893  FAIL_IF_NULL(sig);
1894 
1895  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
1896  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowbitsCompare);
1897  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowvarCompare);
1898  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPktvarCompare);
1899  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPriorityCompare);
1901 
1902  sig = de_ctx->sig_list;
1903 
1904 #ifdef DEBUG
1905  while (sig != NULL) {
1906  printf("sid: %d\n", sig->id);
1907  sig = sig->next;
1908  }
1909 #endif
1910 
1911  sig = de_ctx->sig_list;
1912 
1913  FAIL_IF_NOT(sig->id == 2);
1914  sig = sig->next;
1915  FAIL_IF_NOT(sig->id == 4);
1916  sig = sig->next;
1917  FAIL_IF_NOT(sig->id == 5);
1918  sig = sig->next;
1919  FAIL_IF_NOT(sig->id == 8);
1920  sig = sig->next;
1921  FAIL_IF_NOT(sig->id == 1);
1922  sig = sig->next;
1923  FAIL_IF_NOT(sig->id == 3);
1924  sig = sig->next;
1925  FAIL_IF_NOT(sig->id == 6);
1926  sig = sig->next;
1927  FAIL_IF_NOT(sig->id == 7);
1928  sig = sig->next;
1929 
1930  /* Restore the default pre-order definition */
1935 
1937  PASS;
1938 }
1939 
1940 static int SCSigOrderingTest11(void)
1941 {
1942 
1943  Signature *sig = NULL;
1944 
1946  FAIL_IF(de_ctx == NULL);
1947 
1949  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering set\"; "
1950  "flowbits:isnotset,myflow1; rev:4; sid:1;)");
1951  FAIL_IF_NULL(sig);
1952 
1954  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering unset\"; "
1955  "flowbits:unset,myflow2; rev:4; sid:2;)");
1956  FAIL_IF_NULL(sig);
1957 
1959  "alert tcp any !21:902 -> any any (msg:\"Testing sigordering unset\"; "
1960  "flowbits:isset, myflow1; flowbits:unset,myflow2; rev:4; priority:3; sid:3;)");
1961  FAIL_IF_NULL(sig);
1962 
1963  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByActionCompare);
1964  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowbitsCompare);
1965  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowvarCompare);
1966  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPktvarCompare);
1967  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByPriorityCompare);
1969 
1970  sig = de_ctx->sig_list;
1971 
1972 #ifdef DEBUG
1973  while (sig != NULL) {
1974  printf("sid: %d\n", sig->id);
1975  sig = sig->next;
1976  }
1977 #endif
1978 
1979  sig = de_ctx->sig_list;
1980 
1981  FAIL_IF_NOT(sig->id == 2);
1982  sig = sig->next;
1983  FAIL_IF_NOT(sig->id == 3);
1984  sig = sig->next;
1985  FAIL_IF_NOT(sig->id == 1);
1986  sig = sig->next;
1987 
1989  PASS;
1990 }
1991 
1992 static int SCSigOrderingTest12(void)
1993 {
1994  Signature *sig = NULL;
1995  Packet *p = NULL;
1996  uint8_t buf[] = "test message";
1997  Flow f;
1998  memset(&f, 0, sizeof(f));
1999  FLOW_INITIALIZE(&f);
2000  f.flags |= FLOW_IPV4;
2002  f.proto = IPPROTO_TCP;
2003 
2005  FAIL_IF(de_ctx == NULL);
2006  de_ctx->flags |= DE_QUIET;
2007 
2008  const char *sigs[2];
2009  sigs[0] = "alert tcp any any -> any any (content:\"test\"; dsize:>0; flowbits:isset,one; flowbits:set,two; sid:1;)";
2010  sigs[1] = "alert tcp any any -> any any (content:\"test\"; dsize:>0; flowbits:set,one; sid:2;)";
2011  UTHAppendSigs(de_ctx, sigs, 2);
2012 
2013  sig = de_ctx->sig_list;
2014  FAIL_IF_NULL(sig);
2015  FAIL_IF_NULL(sig->next);
2016  FAIL_IF_NOT_NULL(sig->next->next);
2017  FAIL_IF(de_ctx->signum != 2);
2018 
2020  p = UTHBuildPacket(buf, sizeof(buf), IPPROTO_TCP);
2021  FAIL_IF_NULL(p);
2022 
2023  p->flow = &f;
2027 
2028  UTHMatchPackets(de_ctx, &p, 1);
2029 
2030  uint32_t sids[2] = {1, 2};
2031  uint32_t results[2] = {1, 1};
2032  FAIL_IF_NOT(UTHCheckPacketMatchResults(p, sids, results, 2));
2033 
2034  UTHFreePackets(&p, 1);
2035  FLOW_DESTROY(&f);
2036 
2038  FlowShutdown();
2039  PASS;
2040 }
2041 
2042 /** \test Bug 1061 */
2043 static int SCSigOrderingTest13(void)
2044 {
2045 
2046  Signature *sig = NULL;
2047 
2049  FAIL_IF(de_ctx == NULL);
2050 
2051  sig = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (flowbits:isset,bit1; flowbits:set,bit2; flowbits:set,bit3; sid:6;)");
2052  FAIL_IF_NULL(sig);
2053  sig = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (flowbits:set,bit1; flowbits:set,bit2; sid:7;)");
2054  FAIL_IF_NULL(sig);
2055  sig = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (flowbits:isset,bit1; flowbits:isset,bit2; flowbits:isset,bit3; sid:5;)");
2056  FAIL_IF_NULL(sig);
2057 
2058  SCSigRegisterSignatureOrderingFunc(de_ctx, SCSigOrderByFlowbitsCompare);
2060 
2061 #ifdef DEBUG
2062  sig = de_ctx->sig_list;
2063  while (sig != NULL) {
2064  printf("sid: %d\n", sig->id);
2065  sig = sig->next;
2066  }
2067 #endif
2068 
2069  sig = de_ctx->sig_list;
2070 
2071  FAIL_IF_NOT(sig->id == 7);
2072  sig = sig->next;
2073  FAIL_IF_NOT(sig->id == 6);
2074  sig = sig->next;
2075  FAIL_IF_NOT(sig->id == 5);
2076  sig = sig->next;
2077 
2079  PASS;
2080 }
2081 
2082 #endif
2083 
2085 {
2086 
2087 #ifdef UNITTESTS
2088  UtRegisterTest("SCSigOrderingTest01", SCSigOrderingTest01);
2089  UtRegisterTest("SCSigOrderingTest02", SCSigOrderingTest02);
2090  UtRegisterTest("SCSigOrderingTest03", SCSigOrderingTest03);
2091  UtRegisterTest("SCSigOrderingTest04", SCSigOrderingTest04);
2092  UtRegisterTest("SCSigOrderingTest05", SCSigOrderingTest05);
2093  UtRegisterTest("SCSigOrderingTest06", SCSigOrderingTest06);
2094  UtRegisterTest("SCSigOrderingTest07", SCSigOrderingTest07);
2095  UtRegisterTest("SCSigOrderingTest08", SCSigOrderingTest08);
2096  UtRegisterTest("SCSigOrderingTest09", SCSigOrderingTest09);
2097  UtRegisterTest("SCSigOrderingTest10", SCSigOrderingTest10);
2098  UtRegisterTest("SCSigOrderingTest11", SCSigOrderingTest11);
2099  UtRegisterTest("SCSigOrderingTest12", SCSigOrderingTest12);
2100  UtRegisterTest("SCSigOrderingTest13", SCSigOrderingTest13);
2101 #endif
2102 }
DetectPcreData_::idx
uint8_t idx
Definition: detect-pcre.h:52
DETECT_SIGORDER_IPPAIRBITS
@ DETECT_SIGORDER_IPPAIRBITS
Definition: detect-engine-sigorder.c:79
SCSigSignatureWrapper
struct SCSigSignatureWrapper_ SCSigSignatureWrapper
Signature wrapper used by signature ordering module while ordering signatures.
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:119
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
SignatureInitData_::smlists
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
Definition: detect.h:649
DETECT_FLOWINT_TYPE_SET
#define DETECT_FLOWINT_TYPE_SET
Definition: detect-engine-sigorder.c:62
Flow_::flags
uint64_t flags
Definition: flow.h:403
PKT_HAS_FLOW
#define PKT_HAS_FLOW
Definition: decode.h:1310
flow-util.h
SigFree
void SigFree(DetectEngineCtx *, Signature *)
Definition: detect-parse.c:2126
FLOWINT_MODIFIER_ADD
@ FLOWINT_MODIFIER_ADD
Definition: detect-flowint.h:31
SCSigOrderFunc_::next
struct SCSigOrderFunc_ * next
Definition: detect-engine-sigorder.c:105
ACTION_PASS
#define ACTION_PASS
Definition: action-globals.h:34
ACTION_REJECT
#define ACTION_REJECT
Definition: action-globals.h:31
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
DETECT_FLOWINT_TYPE_READ
#define DETECT_FLOWINT_TYPE_READ
Definition: detect-engine-sigorder.c:60
Signature_::app_progress_hook
uint8_t app_progress_hook
Definition: detect.h:712
Signature_::alproto
AppProto alproto
Definition: detect.h:680
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
FLOWINT_MODIFIER_NE
@ FLOWINT_MODIFIER_NE
Definition: detect-flowint.h:38
Flow_::proto
uint8_t proto
Definition: flow.h:376
DETECT_FLOWBITS_CMD_ISNOTSET
#define DETECT_FLOWBITS_CMD_ISNOTSET
Definition: detect-flowbits.h:30
action-globals.h
Packet_::flags
uint32_t flags
Definition: decode.h:561
type
uint8_t type
Definition: decode-sctp.h:0
Flow_
Flow data structure.
Definition: flow.h:354
ActionOrderVal
uint8_t ActionOrderVal(uint8_t action)
Return the priority associated to an action (to order sigs as specified at config) action_order_sigs ...
Definition: util-action.c:53
DetectSigorderUserDataType
DetectSigorderUserDataType
Different kinds of helper data that can be used by the signature ordering module. Used by the "user" ...
Definition: detect-engine-sigorder.c:73
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:973
DetectFlowintData_
Definition: detect-flowint.h:61
DetectXbitsData_::cmd
uint8_t cmd
Definition: detect-xbits.h:43
DETECT_SIGORDER_FLOWBITS
@ DETECT_SIGORDER_FLOWBITS
Definition: detect-engine-sigorder.c:74
DetectFlowbitsData_::cmd
uint8_t cmd
Definition: detect-flowbits.h:36
DETECT_XBITS_TYPE_SET_READ
#define DETECT_XBITS_TYPE_SET_READ
Definition: detect-engine-sigorder.c:66
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2760
SCSigSignatureWrapper_::next
struct SCSigSignatureWrapper_ * next
Definition: detect-engine-sigorder.c:94
detect-flowint.h
SCSigSignatureOrderingModuleCleanup
void SCSigSignatureOrderingModuleCleanup(DetectEngineCtx *de_ctx)
De-registers all the signature ordering functions registered.
Definition: detect-engine-sigorder.c:937
UTHCheckPacketMatchResults
int UTHCheckPacketMatchResults(Packet *p, uint32_t sids[], uint32_t results[], int numsigs)
UTHCheckPacketMatches: function to check if a packet match some sids.
Definition: util-unittest-helper.c:620
FLOW_PKT_TOSERVER
#define FLOW_PKT_TOSERVER
Definition: flow.h:231
DE_QUIET
#define DE_QUIET
Definition: detect.h:330
DETECT_PKTVAR_TYPE_READ
#define DETECT_PKTVAR_TYPE_READ
Definition: detect-engine-sigorder.c:50
UTHBuildPacket
Packet * UTHBuildPacket(uint8_t *payload, uint16_t payload_len, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
Definition: util-unittest-helper.c:243
SCSigRegisterSignatureOrderingTests
void SCSigRegisterSignatureOrderingTests(void)
Definition: detect-engine-sigorder.c:2084
DETECT_FLOWBITS_CMD_ISSET
#define DETECT_FLOWBITS_CMD_ISSET
Definition: detect-flowbits.h:31
p
Packet * p
Definition: fuzz_iprep.c:21
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:3595
Packet_::flowflags
uint8_t flowflags
Definition: decode.h:546
action_order_sigs
uint8_t action_order_sigs[4]
Definition: util-action.c:40
SCSigSignatureWrapper_::sig
Signature * sig
Definition: detect-engine-sigorder.c:89
detect-pcre.h
FLOW_IPV4
#define FLOW_IPV4
Definition: flow.h:99
DetectXbitsData_
Definition: detect-xbits.h:41
util-unittest.h
util-unittest-helper.h
FAIL_IF_NOT
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:82
DETECT_HOSTBITS
@ DETECT_HOSTBITS
Definition: detect-engine-register.h:70
Signature_::next
struct Signature_ * next
Definition: detect.h:757
DetectFlowbitsData_
Definition: detect-flowbits.h:34
FlowInitConfig
void FlowInitConfig(bool quiet)
initialize the configuration
Definition: flow.c:577
UTHMatchPackets
int UTHMatchPackets(DetectEngineCtx *de_ctx, Packet **p, int num_packets)
Definition: util-unittest-helper.c:729
DETECT_SM_LIST_POSTMATCH
@ DETECT_SM_LIST_POSTMATCH
Definition: detect.h:127
DETECT_FLOWVAR_TYPE_SET
#define DETECT_FLOWVAR_TYPE_SET
Definition: detect-engine-sigorder.c:47
FLOW_INITIALIZE
#define FLOW_INITIALIZE(f)
Definition: flow-util.h:38
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:270
detect-xbits.h
DETECT_XBITS_CMD_ISNOTSET
#define DETECT_XBITS_CMD_ISNOTSET
Definition: detect-xbits.h:30
DETECT_XBITS_TYPE_READ
#define DETECT_XBITS_TYPE_READ
Definition: detect-engine-sigorder.c:65
SIG_TYPE_PKT
@ SIG_TYPE_PKT
Definition: detect.h:72
FAIL_IF_NOT_NULL
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
Definition: util-unittest.h:96
util-debug.h
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:22
DETECT_FLOWINT
@ DETECT_FLOWINT
Definition: detect-engine-register.h:69
DETECT_FLOWVAR
@ DETECT_FLOWVAR
Definition: detect-engine-register.h:67
SCSigOrderSignatures
void SCSigOrderSignatures(DetectEngineCtx *de_ctx)
Orders the signatures.
Definition: detect-engine-sigorder.c:802
SCSigOrderFunc
struct SCSigOrderFunc_ SCSigOrderFunc
Structure holding the signature ordering function used by the signature ordering module.
detect.h
DETECT_FLOWBITS_TYPE_SET_READ
#define DETECT_FLOWBITS_TYPE_SET_READ
Definition: detect-engine-sigorder.c:56
DETECT_SIGORDER_FLOWINT
@ DETECT_SIGORDER_FLOWINT
Definition: detect-engine-sigorder.c:77
SCSigSignatureWrapper_
Signature wrapper used by signature ordering module while ordering signatures.
Definition: detect-engine-sigorder.c:87
SCSigRegisterSignatureOrderingFuncs
void SCSigRegisterSignatureOrderingFuncs(DetectEngineCtx *de_ctx)
Lets you register the Signature ordering functions. The order in which the functions are registered s...
Definition: detect-engine-sigorder.c:917
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:360
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:117
DETECT_XBITS_NOT_USED
#define DETECT_XBITS_NOT_USED
Definition: detect-engine-sigorder.c:64
DETECT_XBITS
@ DETECT_XBITS
Definition: detect-engine-register.h:71
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:359
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:325
Signature_::action
uint8_t action
Definition: detect.h:690
DETECT_FLOWVAR_TYPE_READ
#define DETECT_FLOWVAR_TYPE_READ
Definition: detect-engine-sigorder.c:45
DetectXbitsData_::type
enum VarTypes type
Definition: detect-xbits.h:47
DETECT_SIGORDER_PKTVAR
@ DETECT_SIGORDER_PKTVAR
Definition: detect-engine-sigorder.c:76
Signature_::flags
uint32_t flags
Definition: detect.h:676
DETECT_PKTVAR_NOT_USED
#define DETECT_PKTVAR_NOT_USED
Definition: detect-engine-sigorder.c:49
ACTION_ALERT
#define ACTION_ALERT
Definition: action-globals.h:29
Packet_
Definition: decode.h:515
detect-engine-build.h
FLOWINT_MODIFIER_LE
@ FLOWINT_MODIFIER_LE
Definition: detect-flowint.h:36
DETECT_SIGORDER_HOSTBITS
@ DETECT_SIGORDER_HOSTBITS
Definition: detect-engine-sigorder.c:78
SCSigOrderFunc_
Structure holding the signature ordering function used by the signature ordering module.
Definition: detect-engine-sigorder.c:101
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:754
DetectFlowintData_::modifier
uint8_t modifier
Definition: detect-flowint.h:70
DETECT_FLOWBITS_NOT_USED
#define DETECT_FLOWBITS_NOT_USED
Definition: detect-engine-sigorder.c:54
util-action.h
DETECT_PKTVAR_TYPE_SET
#define DETECT_PKTVAR_TYPE_SET
Definition: detect-engine-sigorder.c:52
detect-flowbits.h
DETECT_PCRE
@ DETECT_PCRE
Definition: detect-engine-register.h:78
FLOWINT_MODIFIER_GT
@ FLOWINT_MODIFIER_GT
Definition: detect-flowint.h:40
DETECT_SIGORDER_FLOWVAR
@ DETECT_SIGORDER_FLOWVAR
Definition: detect-engine-sigorder.c:75
DetectPcreData_::captypes
uint8_t captypes[DETECT_PCRE_CAPTURE_MAX]
Definition: detect-pcre.h:53
FLOWINT_MODIFIER_LT
@ FLOWINT_MODIFIER_LT
Definition: detect-flowint.h:35
Packet_::flow
struct Flow_ * flow
Definition: decode.h:563
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
suricata-common.h
FLOWINT_MODIFIER_SET
@ FLOWINT_MODIFIER_SET
Definition: detect-flowint.h:30
FLOWINT_MODIFIER_ISSET
@ FLOWINT_MODIFIER_ISSET
Definition: detect-flowint.h:42
SigMatch_::type
uint16_t type
Definition: detect.h:357
FlowShutdown
void FlowShutdown(void)
shutdown the flow engine
Definition: flow.c:721
DETECT_FLOWINT_NOT_USED
#define DETECT_FLOWINT_NOT_USED
Definition: detect-engine-sigorder.c:59
ACTION_DROP
#define ACTION_DROP
Definition: action-globals.h:30
DETECT_FLOWINT_TYPE_SET_READ
#define DETECT_FLOWINT_TYPE_SET_READ
Definition: detect-engine-sigorder.c:61
FatalError
#define FatalError(...)
Definition: util-debug.h:517
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:982
FLOWINT_MODIFIER_ISNOTSET
@ FLOWINT_MODIFIER_ISNOTSET
Definition: detect-flowint.h:43
DETECT_FLOWBITS
@ DETECT_FLOWBITS
Definition: detect-engine-register.h:66
Signature_::prio
int prio
Definition: detect.h:723
DETECT_XBITS_TYPE_SET
#define DETECT_XBITS_TYPE_SET
Definition: detect-engine-sigorder.c:67
VAR_TYPE_HOST_BIT
@ VAR_TYPE_HOST_BIT
Definition: util-var.h:41
util-validate.h
detect-engine-sigorder.h
SignatureInitData_::firewall_rule
bool firewall_rule
Definition: detect.h:671
SCSigOrderFunc_::SWCompare
int(* SWCompare)(SCSigSignatureWrapper *sw1, SCSigSignatureWrapper *sw2)
Definition: detect-engine-sigorder.c:103
Signature_::iid
SigIntId iid
Definition: detect.h:687
SCFree
#define SCFree(p)
Definition: util-mem.h:61
DETECT_FLOWVAR_TYPE_SET_READ
#define DETECT_FLOWVAR_TYPE_SET_READ
Definition: detect-engine-sigorder.c:46
Signature_::id
uint32_t id
Definition: detect.h:720
DETECT_FLOWBITS_CMD_UNSET
#define DETECT_FLOWBITS_CMD_UNSET
Definition: detect-flowbits.h:29
detect-parse.h
Signature_
Signature container.
Definition: detect.h:675
SigMatch_
a single match condition for a signature
Definition: detect.h:356
VAR_TYPE_FLOW_VAR
@ VAR_TYPE_FLOW_VAR
Definition: util-var.h:39
DETECT_PKTVAR_TYPE_SET_READ
#define DETECT_PKTVAR_TYPE_SET_READ
Definition: detect-engine-sigorder.c:51
DETECT_XBITS_CMD_ISSET
#define DETECT_XBITS_CMD_ISSET
Definition: detect-xbits.h:31
ALPROTO_UNKNOWN
@ ALPROTO_UNKNOWN
Definition: app-layer-protos.h:29
FLOW_PKT_ESTABLISHED
#define FLOW_PKT_ESTABLISHED
Definition: flow.h:233
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2721
VarTypes
VarTypes
Definition: util-var.h:28
DetectPcreData_
Definition: detect-pcre.h:47
FLOW_QUIET
#define FLOW_QUIET
Definition: flow.h:43
DETECT_XBITS_CMD_SET
#define DETECT_XBITS_CMD_SET
Definition: detect-xbits.h:27
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:975
UTHAppendSigs
int UTHAppendSigs(DetectEngineCtx *de_ctx, const char *sigs[], int numsigs)
UTHAppendSigs: Add sigs to the detection_engine checking for errors.
Definition: util-unittest-helper.c:653
FLOWINT_MODIFIER_EQ
@ FLOWINT_MODIFIER_EQ
Definition: detect-flowint.h:37
DETECT_XBITS_CMD_TOGGLE
#define DETECT_XBITS_CMD_TOGGLE
Definition: detect-xbits.h:28
Signature_::msg
char * msg
Definition: detect.h:743
DETECT_XBITS_CMD_UNSET
#define DETECT_XBITS_CMD_UNSET
Definition: detect-xbits.h:29
VAR_TYPE_IPPAIR_BIT
@ VAR_TYPE_IPPAIR_BIT
Definition: util-var.h:45
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:450
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
Signature_::type
enum SignatureType type
Definition: detect.h:678
DETECT_FLOWBITS_TYPE_SET
#define DETECT_FLOWBITS_TYPE_SET
Definition: detect-engine-sigorder.c:57
DETECT_SIGORDER_MAX
@ DETECT_SIGORDER_MAX
Definition: detect-engine-sigorder.c:80
DetectEngineCtx_::signum
uint32_t signum
Definition: detect.h:994
DETECT_FLOWVAR_NOT_USED
#define DETECT_FLOWVAR_NOT_USED
Definition: detect-engine-sigorder.c:44
SCSigSignatureWrapper_::user
int user[DETECT_SIGORDER_MAX]
Definition: detect-engine-sigorder.c:92
FLOWINT_MODIFIER_SUB
@ FLOWINT_MODIFIER_SUB
Definition: detect-flowint.h:32
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:109
FLOW_DESTROY
#define FLOW_DESTROY(f)
Definition: flow-util.h:119
VAR_TYPE_PKT_VAR
@ VAR_TYPE_PKT_VAR
Definition: util-var.h:33
PKT_STREAM_EST
#define PKT_STREAM_EST
Definition: decode.h:1306
DetectEngineCtx_::sc_sig_order_funcs
struct SCSigOrderFunc_ * sc_sig_order_funcs
Definition: detect.h:997
DETECT_FLOWBITS_CMD_SET
#define DETECT_FLOWBITS_CMD_SET
Definition: detect-flowbits.h:28
FLOWINT_MODIFIER_GE
@ FLOWINT_MODIFIER_GE
Definition: detect-flowint.h:39
DETECT_PKTVAR
@ DETECT_PKTVAR
Definition: detect-engine-register.h:72
DETECT_FLOWBITS_TYPE_READ
#define DETECT_FLOWBITS_TYPE_READ
Definition: detect-engine-sigorder.c:55
UTHFreePackets
void UTHFreePackets(Packet **p, int numpkts)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:455