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