suricata
detect-ipproto.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2022 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Brian Rectanus <brectanu@gmail.com>
22  *
23  * Implements the ip_proto keyword
24  */
25 
26 #include "suricata-common.h"
27 #include "decode.h"
28 #include "detect.h"
29 
30 #include "detect-ipproto.h"
31 
32 #include "detect-parse.h"
33 #include "detect-engine.h"
34 #include "detect-engine-mpm.h"
35 #include "detect-engine-build.h"
36 
37 #include "detect-engine-siggroup.h"
38 #include "detect-engine-address.h"
39 
40 #include "util-byte.h"
41 #include "util-proto-name.h"
42 #include "util-unittest-helper.h"
43 
44 #include "util-debug.h"
45 
46 /**
47  * \brief Regex for parsing our options
48  */
49 #define PARSE_REGEX "^([!<>]?)\\s*([^\\s]+)$"
50 
51 static DetectParseRegex parse_regex;
52 
53 static int DetectIPProtoSetup(DetectEngineCtx *, Signature *, const char *);
54 #ifdef UNITTESTS
55 static void DetectIPProtoRegisterTests(void);
56 #endif
57 static void DetectIPProtoFree(DetectEngineCtx *, void *);
58 
60 {
61  sigmatch_table[DETECT_IPPROTO].name = "ip_proto";
62  sigmatch_table[DETECT_IPPROTO].desc = "match on the IP protocol in the packet-header";
63  sigmatch_table[DETECT_IPPROTO].url = "/rules/header-keywords.html#ip-proto";
65  sigmatch_table[DETECT_IPPROTO].Setup = DetectIPProtoSetup;
66  sigmatch_table[DETECT_IPPROTO].Free = DetectIPProtoFree;
67 #ifdef UNITTESTS
68  sigmatch_table[DETECT_IPPROTO].RegisterTests = DetectIPProtoRegisterTests;
69 #endif
71 
72  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
73 }
74 
75 /**
76  * \internal
77  * \brief Parse ip_proto options string.
78  *
79  * \param optstr Options string to parse
80  *
81  * \return New ip_proto data structure
82  */
83 static DetectIPProtoData *DetectIPProtoParse(const char *optstr)
84 {
85  /* Execute the regex and populate args with captures. */
86  pcre2_match_data *match = NULL;
87  int ret = DetectParsePcreExec(&parse_regex, &match, optstr, 0, 0);
88  if (ret != 3) {
89  SCLogError("pcre_exec parse error, ret"
90  "%" PRId32 ", string %s",
91  ret, optstr);
92  if (match) {
93  pcre2_match_data_free(match);
94  }
95  return NULL;
96  }
97 
98  char *args[2] = { NULL, NULL };
99  DetectIPProtoData *data = NULL;
100 
101  for (int i = 0; i < 2; i++) {
102  const char *str_ptr = NULL;
103  size_t pcre2_len = 0;
104  int res = pcre2_substring_get_bynumber(match, i + 1, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
105  if (res < 0) {
106  SCLogError("pcre2_substring_get_bynumber failed");
107  goto error;
108  }
109  args[i] = (char *)str_ptr;
110  }
111 
112  /* Initialize the data */
113  data = SCCalloc(1, sizeof(DetectIPProtoData));
114  if (unlikely(data == NULL))
115  goto error;
116  data->op = DETECT_IPPROTO_OP_EQ;
117  data->proto = 0;
118 
119  /* Operator */
120  if (*(args[0]) != '\0') {
121  data->op = *(args[0]);
122  }
123 
124  /* Protocol name/number */
125  if (!isdigit((unsigned char)*(args[1]))) {
126  uint8_t proto;
127  if (!SCGetProtoByName(args[1], &proto)) {
128  SCLogError("Unknown protocol name: \"%s\"", args[1]);
129  goto error;
130  }
131  data->proto = proto;
132  }
133  else {
134  if (StringParseUint8(&data->proto, 10, 0, args[1]) <= 0) {
135  SCLogError("Malformed protocol number: %s", args[1]);
136  goto error;
137  }
138  }
139 
140  for (int i = 0; i < 2; i++) {
141  if (args[i] != NULL)
142  pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
143  }
144 
145  pcre2_match_data_free(match);
146  return data;
147 
148 error:
149  if (match) {
150  pcre2_match_data_free(match);
151  }
152  for (int i = 0; i < 2; i++) {
153  if (args[i] != NULL)
154  pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
155  }
156  if (data != NULL)
157  SCFree(data);
158 
159  return NULL;
160 }
161 
162 static int DetectIPProtoTypePresentForOP(Signature *s, uint8_t op)
163 {
164  for (const SigMatch *sm =
166  sm != NULL; sm = SCSigMatchGetPrevByType(sm, DETECT_IPPROTO)) {
167  const DetectIPProtoData *data = (const DetectIPProtoData *)SCSigMatchGetCtx(sm);
168  if (data->op == op)
169  return 1;
170  }
171 
172  return 0;
173 }
174 
175 /**
176  * \internal
177  * \brief Setup ip_proto keyword.
178  *
179  * \param de_ctx Detection engine context
180  * \param s Signature
181  * \param optstr Options string
182  *
183  * \return Non-zero on error
184  */
185 static int DetectIPProtoSetup(DetectEngineCtx *de_ctx, Signature *s, const char *optstr)
186 {
187  int i;
188 
189  DetectIPProtoData *data = DetectIPProtoParse(optstr);
190  if (data == NULL) {
191  return -1;
192  }
193 
194  /* Reset our "any" (or "ip") state: for ipv4, ipv6 and ip cases, the bitfield
195  * s->proto.proto have all bit set to 1 to be able to match any protocols. ipproto
196  * will refined the protocol list and thus it needs to reset the bitfield to zero
197  * before setting the value specified by the ip_proto keyword.
198  */
201  memset(s->init_data->proto.proto, 0x00, sizeof(s->init_data->proto.proto));
203  } else {
204  /* The ipproto engine has a relationship with the protocol that is
205  * set after the action and also the app protocol(that can also be
206  * set through the app-layer-protocol.
207  * An ip_proto keyword can be used only with alert ip, which if
208  * not true we error out on the sig. And hence the init_flag to
209  * indicate this. */
211  SCLogError("Signature can use "
212  "ip_proto keyword only when we use alert ip, "
213  "in which case the _ANY flag is set on the sig "
214  "and the if condition should match.");
215  goto error;
216  }
217  }
218 
219  int eq_set = DetectIPProtoTypePresentForOP(s, DETECT_IPPROTO_OP_EQ);
220  int gt_set = DetectIPProtoTypePresentForOP(s, DETECT_IPPROTO_OP_GT);
221  int lt_set = DetectIPProtoTypePresentForOP(s, DETECT_IPPROTO_OP_LT);
222  int not_set = DetectIPProtoTypePresentForOP(s, DETECT_IPPROTO_OP_NOT);
223 
224  switch (data->op) {
226  if (eq_set || gt_set || lt_set || not_set) {
227  SCLogError("can't use a eq "
228  "ipproto without any operators attached to "
229  "them in the same sig");
230  goto error;
231  }
232  s->init_data->proto.proto[data->proto / 8] |= 1 << (data->proto % 8);
233  break;
234 
236  if (eq_set || gt_set) {
237  SCLogError("can't use a eq or gt "
238  "ipproto along with a greater than ipproto in the "
239  "same sig ");
240  goto error;
241  }
242  if (!lt_set && !not_set) {
243  s->init_data->proto.proto[data->proto / 8] = (uint8_t)(0xfe << (data->proto % 8));
244  for (i = (data->proto / 8) + 1; i < (256 / 8); i++) {
245  s->init_data->proto.proto[i] = 0xff;
246  }
247  } else if (lt_set && !not_set) {
249  while (temp_sm != NULL) {
250  if (temp_sm->type == DETECT_IPPROTO) {
251  break;
252  }
253  temp_sm = temp_sm->next;
254  }
255  if (temp_sm != NULL) {
256  DetectIPProtoData *data_temp = (DetectIPProtoData *)temp_sm->ctx;
257  if (data_temp->proto <= data->proto) {
258  SCLogError("can't have "
259  "both gt and lt ipprotos, with the lt being "
260  "lower than gt value");
261  goto error;
262  } else {
263  for (i = 0; i < (data->proto / 8); i++) {
264  s->init_data->proto.proto[i] = 0;
265  }
266  s->init_data->proto.proto[data->proto / 8] &= 0xfe << (data->proto % 8);
267  for (i = (data->proto / 8) + 1; i < (256 / 8); i++) {
268  s->init_data->proto.proto[i] &= 0xff;
269  }
270  }
271  }
272  } else if (!lt_set && not_set) {
273  for (i = 0; i < (data->proto / 8); i++) {
274  s->init_data->proto.proto[i] = 0;
275  }
276  s->init_data->proto.proto[data->proto / 8] &= 0xfe << (data->proto % 8);
277  for (i = (data->proto / 8) + 1; i < (256 / 8); i++) {
278  s->init_data->proto.proto[i] &= 0xff;
279  }
280  } else {
281  DetectIPProtoData *data_temp;
283  while (temp_sm != NULL) {
284  if (temp_sm->type == DETECT_IPPROTO &&
285  ((DetectIPProtoData *)temp_sm->ctx)->op == DETECT_IPPROTO_OP_LT) {
286  break;
287  }
288  temp_sm = temp_sm->next;
289  }
290  if (temp_sm != NULL) {
291  data_temp = (DetectIPProtoData *)temp_sm->ctx;
292  if (data_temp->proto <= data->proto) {
293  SCLogError("can't have "
294  "both gt and lt ipprotos, with the lt being "
295  "lower than gt value");
296  goto error;
297  } else {
298  for (i = 0; i < (data->proto / 8); i++) {
299  s->init_data->proto.proto[i] = 0;
300  }
301  s->init_data->proto.proto[data->proto / 8] &= 0xfe << (data->proto % 8);
302  for (i = (data->proto / 8) + 1; i < (256 / 8); i++) {
303  s->init_data->proto.proto[i] &= 0xff;
304  }
305  }
306  }
307  }
308  break;
309 
311  if (eq_set || lt_set) {
312  SCLogError("can't use a eq or lt "
313  "ipproto with a less than ipproto in the "
314  "same sig ");
315  goto error;
316  }
317  if (!gt_set && !not_set) {
318  for (i = 0; i < (data->proto / 8); i++) {
319  s->init_data->proto.proto[i] = 0xff;
320  }
321  s->init_data->proto.proto[data->proto / 8] =
322  (uint8_t)(~(0xff << (data->proto % 8)));
323  } else if (gt_set && !not_set) {
325  while (temp_sm != NULL) {
326  if (temp_sm->type == DETECT_IPPROTO) {
327  break;
328  }
329  temp_sm = temp_sm->next;
330  }
331  if (temp_sm != NULL) {
332  DetectIPProtoData *data_temp = (DetectIPProtoData *)temp_sm->ctx;
333  if (data_temp->proto >= data->proto) {
334  SCLogError("can't have "
335  "both gt and lt ipprotos, with the lt being "
336  "lower than gt value");
337  goto error;
338  } else {
339  for (i = 0; i < (data->proto / 8); i++) {
340  s->init_data->proto.proto[i] &= 0xff;
341  }
342  s->init_data->proto.proto[data->proto / 8] &= ~(0xff << (data->proto % 8));
343  for (i = (data->proto / 8) + 1; i < 256 / 8; i++) {
344  s->init_data->proto.proto[i] = 0;
345  }
346  }
347  }
348  } else if (!gt_set && not_set) {
349  for (i = 0; i < (data->proto / 8); i++) {
350  s->init_data->proto.proto[i] &= 0xFF;
351  }
352  s->init_data->proto.proto[data->proto / 8] &= ~(0xff << (data->proto % 8));
353  for (i = (data->proto / 8) + 1; i < (256 / 8); i++) {
354  s->init_data->proto.proto[i] = 0;
355  }
356  } else {
357  DetectIPProtoData *data_temp;
359  while (temp_sm != NULL) {
360  if (temp_sm->type == DETECT_IPPROTO &&
361  ((DetectIPProtoData *)temp_sm->ctx)->op == DETECT_IPPROTO_OP_GT) {
362  break;
363  }
364  temp_sm = temp_sm->next;
365  }
366  if (temp_sm != NULL) {
367  data_temp = (DetectIPProtoData *)temp_sm->ctx;
368  if (data_temp->proto >= data->proto) {
369  SCLogError("can't have "
370  "both gt and lt ipprotos, with the lt being "
371  "lower than gt value");
372  goto error;
373  } else {
374  for (i = 0; i < (data->proto / 8); i++) {
375  s->init_data->proto.proto[i] &= 0xFF;
376  }
377  s->init_data->proto.proto[data->proto / 8] &= ~(0xff << (data->proto % 8));
378  for (i = (data->proto / 8) + 1; i < (256 / 8); i++) {
379  s->init_data->proto.proto[i] = 0;
380  }
381  }
382  }
383  }
384  break;
385 
387  if (eq_set) {
388  SCLogError("can't use a eq "
389  "ipproto along with a not ipproto in the "
390  "same sig ");
391  goto error;
392  }
393  if (!gt_set && !lt_set && !not_set) {
394  for (i = 0; i < (data->proto / 8); i++) {
395  s->init_data->proto.proto[i] = 0xff;
396  }
397  s->init_data->proto.proto[data->proto / 8] = (uint8_t)(~(1 << (data->proto % 8)));
398  for (i = (data->proto / 8) + 1; i < (256 / 8); i++) {
399  s->init_data->proto.proto[i] = 0xff;
400  }
401  } else {
402  for (i = 0; i < (data->proto / 8); i++) {
403  s->init_data->proto.proto[i] &= 0xff;
404  }
405  s->init_data->proto.proto[data->proto / 8] &= ~(1 << (data->proto % 8));
406  for (i = (data->proto / 8) + 1; i < (256 / 8); i++) {
407  s->init_data->proto.proto[i] &= 0xff;
408  }
409  }
410  break;
411  }
412 
414  de_ctx, s, DETECT_IPPROTO, (SigMatchCtx *)data, DETECT_SM_LIST_MATCH) == NULL) {
415  goto error;
416  }
418 
419  return 0;
420 
421  error:
422 
423  DetectIPProtoFree(de_ctx, data);
424  return -1;
425 }
426 
428 {
430 
431  while (sm != NULL) {
432  if (sm->type != DETECT_IPPROTO) {
433  sm = sm->next;
434  continue;
435  }
436  SigMatch *tmp_sm = sm->next;
438  SigMatchFree(de_ctx, sm);
439  sm = tmp_sm;
440  }
441 }
442 
443 static void DetectIPProtoFree(DetectEngineCtx *de_ctx, void *ptr)
444 {
445  DetectIPProtoData *data = (DetectIPProtoData *)ptr;
446  if (data) {
447  SCFree(data);
448  }
449 }
450 
451 /* UNITTESTS */
452 #ifdef UNITTESTS
453 #include "detect-engine-alert.h"
454 
455 /**
456  * \test DetectIPProtoTestParse01 is a test for an invalid proto number
457  */
458 static int DetectIPProtoTestParse01(void)
459 {
460  DetectIPProtoData *data = DetectIPProtoParse("999");
461  FAIL_IF_NOT(data == NULL);
462  PASS;
463 }
464 
465 /**
466  * \test DetectIPProtoTestParse02 is a test for an invalid proto name
467  */
468 static int DetectIPProtoTestParse02(void)
469 {
470  DetectIPProtoData *data = DetectIPProtoParse("foobarbooeek");
471  FAIL_IF_NOT(data == NULL);
472  PASS;
473 }
474 
475 /**
476  * \test DetectIPProtoTestSetup01 is a test for a protocol number
477  */
478 static int DetectIPProtoTestSetup01(void)
479 {
480  const char *value_str = "14";
481  int value;
482  FAIL_IF(StringParseInt32(&value, 10, 0, (const char *)value_str) < 0);
483  int i;
484 
485  Signature *sig = SigAlloc();
486  FAIL_IF_NULL(sig);
487 
490  DetectIPProtoSetup(NULL, sig, value_str);
491  for (i = 0; i < (value / 8); i++) {
492  FAIL_IF(sig->init_data->proto.proto[i] != 0);
493  }
494  FAIL_IF(sig->init_data->proto.proto[value / 8] != 0x40);
495  for (i = (value / 8) + 1; i < (256 / 8); i++) {
496  FAIL_IF(sig->init_data->proto.proto[i] != 0);
497  }
498  SigFree(NULL, sig);
499  PASS;
500 }
501 
502 /**
503  * \test DetectIPProtoTestSetup02 is a test for a protocol name
504  */
505 static int DetectIPProtoTestSetup02(void)
506 {
507  int result = 0;
508  Signature *sig = NULL;
509  const char *value_str = "tcp";
510  struct protoent *pent = getprotobyname(value_str);
511  if (pent == NULL) {
512  goto end;
513  }
514  uint8_t value = (uint8_t)pent->p_proto;
515  int i;
516 
517  if ((sig = SigAlloc()) == NULL)
518  goto end;
519 
522  DetectIPProtoSetup(NULL, sig, value_str);
523  for (i = 0; i < (value / 8); i++) {
524  if (sig->init_data->proto.proto[i] != 0)
525  goto end;
526  }
527  if (sig->init_data->proto.proto[value / 8] != 0x40) {
528  goto end;
529  }
530  for (i = (value / 8) + 1; i < (256 / 8); i++) {
531  if (sig->init_data->proto.proto[i] != 0)
532  goto end;
533  }
534 
535  result = 1;
536 
537  end:
538  if (sig != NULL)
539  SigFree(NULL, sig);
540  return result;
541 }
542 
543 /**
544  * \test DetectIPProtoTestSetup03 is a test for a < operator
545  */
546 static int DetectIPProtoTestSetup03(void)
547 {
548  int result = 0;
549  Signature *sig;
550  const char *value_str = "<14";
551  int value = 14;
552  int i;
553 
554  if ((sig = SigAlloc()) == NULL)
555  goto end;
556 
559  DetectIPProtoSetup(NULL, sig, value_str);
560  for (i = 0; i < (value / 8); i++) {
561  if (sig->init_data->proto.proto[i] != 0xFF)
562  goto end;
563  }
564  if (sig->init_data->proto.proto[value / 8] != 0x3F) {
565  goto end;
566  }
567  for (i = (value / 8) + 1; i < (256 / 8); i++) {
568  if (sig->init_data->proto.proto[i] != 0)
569  goto end;
570  }
571 
572  result = 1;
573 
574  end:
575  SigFree(NULL, sig);
576  return result;
577 }
578 
579 /**
580  * \test DetectIPProtoTestSetup04 is a test for a > operator
581  */
582 static int DetectIPProtoTestSetup04(void)
583 {
584  int result = 0;
585  Signature *sig;
586  const char *value_str = ">14";
587  int value = 14;
588  int i;
589 
590  if ((sig = SigAlloc()) == NULL)
591  goto end;
592 
595  DetectIPProtoSetup(NULL, sig, value_str);
596  for (i = 0; i < (value / 8); i++) {
597  if (sig->init_data->proto.proto[i] != 0)
598  goto end;
599  }
600  if (sig->init_data->proto.proto[value / 8] != 0x80) {
601  goto end;
602  }
603  for (i = (value / 8) + 1; i < (256 / 8); i++) {
604  if (sig->init_data->proto.proto[i] != 0xFF)
605  goto end;
606  }
607 
608  result = 1;
609 
610  end:
611  SigFree(NULL, sig);
612  return result;
613 }
614 
615 /**
616  * \test DetectIPProtoTestSetup05 is a test for a ! operator
617  */
618 static int DetectIPProtoTestSetup05(void)
619 {
620  int result = 0;
621  Signature *sig;
622  const char *value_str = "!14";
623  int value = 14;
624  int i;
625 
626  if ((sig = SigAlloc()) == NULL)
627  goto end;
628 
631  DetectIPProtoSetup(NULL, sig, value_str);
632  for (i = 0; i < (value / 8); i++) {
633  if (sig->init_data->proto.proto[i] != 0xFF)
634  goto end;
635  }
636  if (sig->init_data->proto.proto[value / 8] != 0xBF) {
637  goto end;
638  }
639  for (i = (value / 8) + 1; i < (256 / 8); i++) {
640  if (sig->init_data->proto.proto[i] != 0xFF)
641  goto end;
642  }
643 
644  result = 1;
645 
646  end:
647  SigFree(NULL, sig);
648  return result;
649 }
650 
651 /**
652  * \test Negative test.
653  */
654 static int DetectIPProtoTestSetup06(void)
655 {
656  int result = 0;
657  Signature *sig;
658  const char *value1_str = "14";
659  const char *value2_str = "15";
660 
661  if ((sig = SigAlloc()) == NULL)
662  goto end;
663 
666  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
667  goto end;
668  if (DetectIPProtoSetup(NULL, sig, value2_str) != -1)
669  goto end;
670 
671  result = 1;
672 
673  end:
674  SigFree(NULL, sig);
675  return result;
676 }
677 
678 /**
679  * \test Negative test.
680  */
681 static int DetectIPProtoTestSetup07(void)
682 {
683  int result = 0;
684  Signature *sig;
685  const char *value1_str = "14";
686  const char *value2_str = "<15";
687 
688  if ((sig = SigAlloc()) == NULL)
689  goto end;
690 
693  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
694  goto end;
695  if (DetectIPProtoSetup(NULL, sig, value2_str) != -1)
696  goto end;
697 
698  result = 1;
699 
700  end:
701  SigFree(NULL, sig);
702  return result;
703 }
704 
705 /**
706  * \test Negative test.
707  */
708 static int DetectIPProtoTestSetup08(void)
709 {
710  int result = 0;
711  Signature *sig;
712  const char *value1_str = "14";
713  const char *value2_str = ">15";
714 
715  if ((sig = SigAlloc()) == NULL)
716  goto end;
717 
720  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
721  goto end;
722  if (DetectIPProtoSetup(NULL, sig, value2_str) != -1)
723  goto end;
724 
725  result = 1;
726 
727  end:
728  SigFree(NULL, sig);
729  return result;
730 }
731 
732 /**
733  * \test Negative test.
734  */
735 static int DetectIPProtoTestSetup09(void)
736 {
737  int result = 0;
738  Signature *sig;
739  const char *value1_str = "14";
740  const char *value2_str = "!15";
741 
742  if ((sig = SigAlloc()) == NULL)
743  goto end;
744 
747  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
748  goto end;
749  if (DetectIPProtoSetup(NULL, sig, value2_str) != -1)
750  goto end;
751 
752  result = 1;
753 
754  end:
755  SigFree(NULL, sig);
756  return result;
757 }
758 
759 /**
760  * \test Negative test.
761  */
762 static int DetectIPProtoTestSetup10(void)
763 {
764  int result = 0;
765  Signature *sig;
766  const char *value1_str = ">14";
767  const char *value2_str = "15";
768 
769  if ((sig = SigAlloc()) == NULL)
770  goto end;
771 
774  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
775  goto end;
776  if (DetectIPProtoSetup(NULL, sig, value2_str) != -1)
777  goto end;
778 
779  result = 1;
780 
781  end:
782  SigFree(NULL, sig);
783  return result;
784 }
785 
786 /**
787  * \test Negative test.
788  */
789 static int DetectIPProtoTestSetup11(void)
790 {
791  int result = 0;
792  Signature *sig;
793  const char *value1_str = "<14";
794  const char *value2_str = "15";
795 
796  if ((sig = SigAlloc()) == NULL)
797  goto end;
798 
801  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
802  goto end;
803  if (DetectIPProtoSetup(NULL, sig, value2_str) != -1)
804  goto end;
805 
806  result = 1;
807 
808  end:
809  SigFree(NULL, sig);
810  return result;
811 }
812 
813 /**
814  * \test Negative test.
815  */
816 static int DetectIPProtoTestSetup12(void)
817 {
818  int result = 0;
819  Signature *sig;
820  const char *value1_str = "!14";
821  const char *value2_str = "15";
822 
823  if ((sig = SigAlloc()) == NULL)
824  goto end;
825 
828  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
829  goto end;
830  if (DetectIPProtoSetup(NULL, sig, value2_str) != -1)
831  goto end;
832 
833  result = 1;
834 
835  end:
836  SigFree(NULL, sig);
837  return result;
838 }
839 
840 /**
841  * \test Negative test.
842  */
843 static int DetectIPProtoTestSetup13(void)
844 {
845  int result = 0;
846  Signature *sig;
847  const char *value1_str = ">14";
848  const char *value2_str = ">15";
849 
850  if ((sig = SigAlloc()) == NULL)
851  goto end;
852 
855  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
856  goto end;
857  if (DetectIPProtoSetup(NULL, sig, value2_str) != -1)
858  goto end;
859 
860  result = 1;
861 
862  end:
863  SigFree(NULL, sig);
864  return result;
865 }
866 
867 static int DetectIPProtoTestSetup14(void)
868 {
869  int result = 0;
870  Signature *sig;
871  const char *value1_str = "<14";
872  const char *value2_str = "<15";
873 
874  if ((sig = SigAlloc()) == NULL)
875  goto end;
876 
879  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
880  goto end;
881  if (DetectIPProtoSetup(NULL, sig, value2_str) != -1)
882  goto end;
883 
884  result = 1;
885 
886  end:
887  SigFree(NULL, sig);
888  return result;
889 }
890 
891 static int DetectIPProtoTestSetup15(void)
892 {
893  int result = 0;
894  Signature *sig;
895  const char *value1_str = "<14";
896  int value1 = 14;
897  const char *value2_str = ">34";
898  int i;
899 
900  if ((sig = SigAlloc()) == NULL)
901  goto end;
902 
905  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
906  goto end;
907  for (i = 0; i < (value1 / 8); i++) {
908  if (sig->init_data->proto.proto[i] != 0xFF)
909  goto end;
910  }
911  if (sig->init_data->proto.proto[value1 / 8] != 0x3F) {
912  goto end;
913  }
914  for (i = (value1 / 8) + 1; i < (256 / 8); i++) {
915  if (sig->init_data->proto.proto[i] != 0)
916  goto end;
917  }
918  if (DetectIPProtoSetup(NULL, sig, value2_str) == 0)
919  goto end;
920 
921  result = 1;
922 
923  end:
924  SigFree(NULL, sig);
925  return result;
926 }
927 
928 static int DetectIPProtoTestSetup16(void)
929 {
930  int result = 0;
931  Signature *sig;
932  const char *value1_str = "<14";
933  const char *value2_str = ">34";
934  int value2 = 34;
935  int i;
936 
937  if ((sig = SigAlloc()) == NULL)
938  goto end;
939 
942  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
943  goto end;
944  for (i = 0; i < (value2 / 8); i++) {
945  if (sig->init_data->proto.proto[i] != 0)
946  goto end;
947  }
948  if (sig->init_data->proto.proto[value2 / 8] != 0xF8) {
949  goto end;
950  }
951  for (i = (value2 / 8) + 1; i < (256 / 8); i++) {
952  if (sig->init_data->proto.proto[i] != 0xFF)
953  goto end;
954  }
955  if (DetectIPProtoSetup(NULL, sig, value1_str) == 0)
956  goto end;
957 
958  result = 1;
959 
960  end:
961  SigFree(NULL, sig);
962  return result;
963 }
964 
965 static int DetectIPProtoTestSetup17(void)
966 {
967  int result = 0;
968  Signature *sig;
969  const char *value1_str = "<11";
970  int value1 = 11;
971  const char *value2_str = ">13";
972  int i;
973 
974  if ((sig = SigAlloc()) == NULL)
975  goto end;
976 
979  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
980  goto end;
981  for (i = 0; i < (value1 / 8); i++) {
982  if (sig->init_data->proto.proto[i] != 0xFF)
983  goto end;
984  }
985  if (sig->init_data->proto.proto[value1 / 8] != 0x07) {
986  goto end;
987  }
988  for (i = (value1 / 8) + 1; i < (256 / 8); i++) {
989  if (sig->init_data->proto.proto[i] != 0)
990  goto end;
991  }
992  if (DetectIPProtoSetup(NULL, sig, value2_str) == 0)
993  goto end;
994 
995  result = 1;
996 
997  end:
998  SigFree(NULL, sig);
999  return result;
1000 }
1001 
1002 static int DetectIPProtoTestSetup18(void)
1003 {
1004  int result = 0;
1005  Signature *sig;
1006  const char *value1_str = "<11";
1007  const char *value2_str = ">13";
1008  int value2 = 13;
1009  int i;
1010 
1011  if ((sig = SigAlloc()) == NULL)
1012  goto end;
1013 
1016  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1017  goto end;
1018  for (i = 0; i < (value2 / 8); i++) {
1019  if (sig->init_data->proto.proto[i] != 0)
1020  goto end;
1021  }
1022  if (sig->init_data->proto.proto[value2 / 8] != 0xC0) {
1023  goto end;
1024  }
1025  for (i = (value2 / 8) + 1; i < (256 / 8); i++) {
1026  if (sig->init_data->proto.proto[i] != 0xFF)
1027  goto end;
1028  }
1029  if (DetectIPProtoSetup(NULL, sig, value1_str) == 0)
1030  goto end;
1031 
1032  result = 1;
1033 
1034  end:
1035  SigFree(NULL, sig);
1036  return result;
1037 }
1038 
1039 static int DetectIPProtoTestSetup19(void)
1040 {
1041  int result = 0;
1042  Signature *sig;
1043  const char *value1_str = "<11";
1044  int value1 = 11;
1045  const char *value2_str = "!13";
1046  const char *value3_str = ">36";
1047  int i;
1048 
1049  if ((sig = SigAlloc()) == NULL)
1050  goto end;
1051 
1054  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
1055  goto end;
1056  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1057  goto end;
1058  for (i = 0; i < (value1 / 8); i++) {
1059  if (sig->init_data->proto.proto[i] != 0xFF)
1060  goto end;
1061  }
1062  if (sig->init_data->proto.proto[value1 / 8] != 0x07) {
1063  goto end;
1064  }
1065  for (i = (value1 / 8) + 1; i < (256 / 8); i++) {
1066  if (sig->init_data->proto.proto[i] != 0)
1067  goto end;
1068  }
1069  if (DetectIPProtoSetup(NULL, sig, value3_str) == 0)
1070  goto end;
1071 
1072  result = 1;
1073 
1074  end:
1075  SigFree(NULL, sig);
1076  return result;
1077 }
1078 
1079 static int DetectIPProtoTestSetup20(void)
1080 {
1081  int result = 0;
1082  Signature *sig;
1083  const char *value1_str = "<11";
1084  int value1 = 11;
1085  const char *value3_str = ">36";
1086  int i;
1087 
1088  if ((sig = SigAlloc()) == NULL)
1089  goto end;
1090 
1093  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
1094  goto end;
1095  for (i = 0; i < (value1 / 8); i++) {
1096  if (sig->init_data->proto.proto[i] != 0xFF)
1097  goto end;
1098  }
1099  if (sig->init_data->proto.proto[value1 / 8] != 0x07) {
1100  goto end;
1101  }
1102  for (i = (value1 / 8) + 1; i < (256 / 8); i++) {
1103  if (sig->init_data->proto.proto[i] != 0)
1104  goto end;
1105  }
1106  if (DetectIPProtoSetup(NULL, sig, value3_str) == 0)
1107  goto end;
1108 
1109  result = 1;
1110 
1111  end:
1112  SigFree(NULL, sig);
1113  return result;
1114 }
1115 
1116 static int DetectIPProtoTestSetup21(void)
1117 {
1118  int result = 0;
1119  Signature *sig;
1120  const char *value1_str = "<11";
1121  int value1 = 11;
1122  const char *value2_str = "!13";
1123  const char *value3_str = ">36";
1124  int i;
1125 
1126  if ((sig = SigAlloc()) == NULL)
1127  goto end;
1128 
1131  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1132  goto end;
1133  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
1134  goto end;
1135  for (i = 0; i < (value1 / 8); i++) {
1136  if (sig->init_data->proto.proto[i] != 0xFF)
1137  goto end;
1138  }
1139  if (sig->init_data->proto.proto[value1 / 8] != 0x07) {
1140  goto end;
1141  }
1142  for (i = (value1 / 8) + 1; i < (256 / 8); i++) {
1143  if (sig->init_data->proto.proto[i] != 0)
1144  goto end;
1145  }
1146  if (DetectIPProtoSetup(NULL, sig, value3_str) == 0)
1147  goto end;
1148 
1149  result = 1;
1150 
1151  end:
1152  SigFree(NULL, sig);
1153  return result;
1154 }
1155 
1156 static int DetectIPProtoTestSetup22(void)
1157 {
1158  int result = 0;
1159  Signature *sig;
1160  const char *value1_str = "<11";
1161  const char *value2_str = "!13";
1162  const char *value3_str = ">36";
1163  int value3 = 36;
1164  int i;
1165 
1166  if ((sig = SigAlloc()) == NULL)
1167  goto end;
1168 
1171  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1172  goto end;
1173  if (DetectIPProtoSetup(NULL, sig, value3_str) != 0)
1174  goto end;
1175  for (i = 0; i < (value3 / 8); i++) {
1176  if (sig->init_data->proto.proto[i] != 0)
1177  goto end;
1178  }
1179  if (sig->init_data->proto.proto[value3 / 8] != 0xE0) {
1180  goto end;
1181  }
1182  for (i = (value3 / 8) + 1; i < (256 / 8); i++) {
1183  if (sig->init_data->proto.proto[i] != 0xFF)
1184  goto end;
1185  }
1186  if (DetectIPProtoSetup(NULL, sig, value1_str) == 0)
1187  goto end;
1188 
1189  result = 1;
1190 
1191  end:
1192  SigFree(NULL, sig);
1193  return result;
1194 }
1195 
1196 static int DetectIPProtoTestSetup23(void)
1197 {
1198  int result = 0;
1199  Signature *sig;
1200  const char *value1_str = "<11";
1201  const char *value3_str = ">36";
1202  int value3 = 36;
1203  int i;
1204 
1205  if ((sig = SigAlloc()) == NULL)
1206  goto end;
1207 
1210  if (DetectIPProtoSetup(NULL, sig, value3_str) != 0)
1211  goto end;
1212  for (i = 0; i < (value3 / 8); i++) {
1213  if (sig->init_data->proto.proto[i] != 0)
1214  goto end;
1215  }
1216  if (sig->init_data->proto.proto[value3 / 8] != 0xE0) {
1217  goto end;
1218  }
1219  for (i = (value3 / 8) + 1; i < (256 / 8); i++) {
1220  if (sig->init_data->proto.proto[i] != 0xFF)
1221  goto end;
1222  }
1223  if (DetectIPProtoSetup(NULL, sig, value1_str) == 0)
1224  goto end;
1225 
1226  result = 1;
1227 
1228  end:
1229  SigFree(NULL, sig);
1230  return result;
1231 }
1232 
1233 static int DetectIPProtoTestSetup24(void)
1234 {
1235  int result = 0;
1236  Signature *sig;
1237  const char *value1_str = "<11";
1238  const char *value2_str = "!13";
1239  const char *value3_str = ">36";
1240  int value3 = 36;
1241  int i;
1242 
1243  if ((sig = SigAlloc()) == NULL)
1244  goto end;
1245 
1248  if (DetectIPProtoSetup(NULL, sig, value3_str) != 0)
1249  goto end;
1250  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1251  goto end;
1252  for (i = 0; i < (value3 / 8); i++) {
1253  if (sig->init_data->proto.proto[i] != 0)
1254  goto end;
1255  }
1256  if (sig->init_data->proto.proto[value3 / 8] != 0xE0) {
1257  goto end;
1258  }
1259  for (i = (value3 / 8) + 1; i < (256 / 8); i++) {
1260  if (sig->init_data->proto.proto[i] != 0xFF)
1261  goto end;
1262  }
1263  if (DetectIPProtoSetup(NULL, sig, value1_str) == 0)
1264  goto end;
1265 
1266  result = 1;
1267 
1268  end:
1269  SigFree(NULL, sig);
1270  return result;
1271 }
1272 
1273 static int DetectIPProtoTestSetup33(void)
1274 {
1275  int result = 0;
1276  Signature *sig;
1277  const char *value1_str = "<11";
1278  int value1 = 11;
1279  const char *value2_str = "!34";
1280  const char *value3_str = ">36";
1281  int i;
1282 
1283  if ((sig = SigAlloc()) == NULL)
1284  goto end;
1285 
1288  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1289  goto end;
1290  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
1291  goto end;
1292  for (i = 0; i < (value1 / 8); i++) {
1293  if (sig->init_data->proto.proto[i] != 0xFF)
1294  goto end;
1295  }
1296  if (sig->init_data->proto.proto[value1 / 8] != 0x07) {
1297  goto end;
1298  }
1299  for (i = (value1 / 8) + 1; i < (256 / 8); i++) {
1300  if (sig->init_data->proto.proto[i] != 0)
1301  goto end;
1302  }
1303  if (DetectIPProtoSetup(NULL, sig, value3_str) == 0)
1304  goto end;
1305 
1306  result = 1;
1307 
1308  end:
1309  SigFree(NULL, sig);
1310  return result;
1311 }
1312 
1313 static int DetectIPProtoTestSetup34(void)
1314 {
1315  int result = 0;
1316  Signature *sig;
1317  const char *value1_str = "<11";
1318  int value1 = 11;
1319  const char *value2_str = "!34";
1320  const char *value3_str = ">36";
1321  int value3 = 36;
1322  int i;
1323 
1324  if ((sig = SigAlloc()) == NULL)
1325  goto end;
1326 
1329  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1330  goto end;
1331  if (DetectIPProtoSetup(NULL, sig, value3_str) != 0)
1332  goto end;
1333  for (i = 0; i < (value1 / 8); i++) {
1334  if (sig->init_data->proto.proto[i] != 0)
1335  goto end;
1336  }
1337  if (sig->init_data->proto.proto[value3 / 8] != 0xE0) {
1338  goto end;
1339  }
1340  for (i = (value3 / 8) + 1; i < (256 / 8); i++) {
1341  if (sig->init_data->proto.proto[i] != 0xFF)
1342  goto end;
1343  }
1344  if (DetectIPProtoSetup(NULL, sig, value1_str) == 0)
1345  goto end;
1346 
1347  result = 1;
1348 
1349  end:
1350  SigFree(NULL, sig);
1351  return result;
1352 }
1353 
1354 static int DetectIPProtoTestSetup36(void)
1355 {
1356  int result = 0;
1357  Signature *sig;
1358  const char *value1_str = "<11";
1359  const char *value2_str = "!34";
1360  const char *value3_str = ">36";
1361  int value3 = 36;
1362  int i;
1363 
1364  if ((sig = SigAlloc()) == NULL)
1365  goto end;
1366 
1369  if (DetectIPProtoSetup(NULL, sig, value3_str) != 0)
1370  goto end;
1371  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1372  goto end;
1373  for (i = 0; i < (value3 / 8); i++) {
1374  if (sig->init_data->proto.proto[i] != 0)
1375  goto end;
1376  }
1377  if (sig->init_data->proto.proto[value3 / 8] != 0xE0) {
1378  goto end;
1379  }
1380  for (i = (value3 / 8) + 1; i < (256 / 8); i++) {
1381  if (sig->init_data->proto.proto[i] != 0xFF)
1382  goto end;
1383  }
1384  if (DetectIPProtoSetup(NULL, sig, value1_str) == 0)
1385  goto end;
1386 
1387  result = 1;
1388 
1389  end:
1390  SigFree(NULL, sig);
1391  return result;
1392 }
1393 
1394 static int DetectIPProtoTestSetup43(void)
1395 {
1396  int result = 0;
1397  Signature *sig;
1398  const char *value1_str = "!4";
1399  int value1 = 4;
1400  const char *value2_str = "<13";
1401  int value2 = 13;
1402  const char *value3_str = ">34";
1403  int i;
1404 
1405  if ((sig = SigAlloc()) == NULL)
1406  goto end;
1407 
1410  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
1411  goto end;
1412  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1413  goto end;
1414  if (sig->init_data->proto.proto[value1 / 8] != 0xEF) {
1415  goto end;
1416  }
1417  for (i = (value1 / 8) + 1; i < (value2 / 8); i++) {
1418  if (sig->init_data->proto.proto[i] != 0xFF)
1419  goto end;
1420  }
1421  if (sig->init_data->proto.proto[value2 / 8] != 0x1F) {
1422  goto end;
1423  }
1424  for (i = (value2 / 8) + 1; i < 256 / 8; i++) {
1425  if (sig->init_data->proto.proto[i] != 0)
1426  goto end;
1427  }
1428  if (DetectIPProtoSetup(NULL, sig, value3_str) == 0)
1429  goto end;
1430 
1431  result = 1;
1432 
1433  end:
1434  SigFree(NULL, sig);
1435  return result;
1436 }
1437 
1438 static int DetectIPProtoTestSetup44(void)
1439 {
1440  int result = 0;
1441  Signature *sig;
1442  const char *value1_str = "!4";
1443  const char *value2_str = "<13";
1444  const char *value3_str = ">34";
1445  int value3 = 34;
1446  int i;
1447 
1448  if ((sig = SigAlloc()) == NULL)
1449  goto end;
1450 
1453  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
1454  goto end;
1455  if (DetectIPProtoSetup(NULL, sig, value3_str) != 0)
1456  goto end;
1457  for (i = 0; i < (value3 / 8); i++) {
1458  if (sig->init_data->proto.proto[i] != 0)
1459  goto end;
1460  }
1461  if (sig->init_data->proto.proto[value3 / 8] != 0xF8) {
1462  goto end;
1463  }
1464  for (i = (value3 / 8) + 1; i < 256 / 8; i++) {
1465  if (sig->init_data->proto.proto[i] != 0xFF)
1466  goto end;
1467  }
1468  if (DetectIPProtoSetup(NULL, sig, value2_str) == 0)
1469  goto end;
1470 
1471  result = 1;
1472 
1473  end:
1474  SigFree(NULL, sig);
1475  return result;
1476 }
1477 
1478 static int DetectIPProtoTestSetup45(void)
1479 {
1480  int result = 0;
1481  Signature *sig;
1482  const char *value1_str = "!4";
1483  int value1 = 4;
1484  const char *value2_str = "<13";
1485  int value2 = 13;
1486  const char *value3_str = ">34";
1487  int i;
1488 
1489  if ((sig = SigAlloc()) == NULL)
1490  goto end;
1491 
1494  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1495  goto end;
1496  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
1497  goto end;
1498  if (sig->init_data->proto.proto[value1 / 8] != 0xEF) {
1499  goto end;
1500  }
1501  for (i = (value1 / 8) + 1; i < (value2 / 8); i++) {
1502  if (sig->init_data->proto.proto[i] != 0xFF)
1503  goto end;
1504  }
1505  if (sig->init_data->proto.proto[value2 / 8] != 0x1F) {
1506  goto end;
1507  }
1508  for (i = (value2 / 8) + 1; i < 256 / 8; i++) {
1509  if (sig->init_data->proto.proto[i] != 0)
1510  goto end;
1511  }
1512  if (DetectIPProtoSetup(NULL, sig, value3_str) == 0)
1513  goto end;
1514 
1515  result = 1;
1516 
1517  end:
1518  SigFree(NULL, sig);
1519  return result;
1520 }
1521 
1522 static int DetectIPProtoTestSetup56(void)
1523 {
1524  int result = 0;
1525  Signature *sig;
1526  const char *value1_str = "<13";
1527  int value1 = 13;
1528  const char *value2_str = ">34";
1529  const char *value3_str = "!37";
1530  int i;
1531 
1532  if ((sig = SigAlloc()) == NULL)
1533  goto end;
1534 
1537  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
1538  goto end;
1539  if (DetectIPProtoSetup(NULL, sig, value3_str) != 0)
1540  goto end;
1541  for (i = 0; i < (value1 / 8); i++) {
1542  if (sig->init_data->proto.proto[i] != 0xFF)
1543  goto end;
1544  }
1545  if (sig->init_data->proto.proto[value1 / 8] != 0x1F) {
1546  goto end;
1547  }
1548  for (i = (value1 / 8) + 1; i < 256 / 8; i++) {
1549  if (sig->init_data->proto.proto[i] != 0)
1550  goto end;
1551  }
1552  if (DetectIPProtoSetup(NULL, sig, value2_str) == 0)
1553  goto end;
1554 
1555  result = 1;
1556 
1557  end:
1558  SigFree(NULL, sig);
1559  return result;
1560 }
1561 
1562 static int DetectIPProtoTestSetup75(void)
1563 {
1564  int result = 0;
1565  Signature *sig;
1566  const char *value1_str = "!8";
1567  const char *value2_str = ">10";
1568  int value2 = 10;
1569  int i;
1570 
1571  if ((sig = SigAlloc()) == NULL)
1572  goto end;
1573 
1576  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
1577  goto end;
1578  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1579  goto end;
1580  for (i = 0; i < (value2 / 8); i++) {
1581  if (sig->init_data->proto.proto[i] != 0)
1582  goto end;
1583  }
1584  if (sig->init_data->proto.proto[value2 / 8] != 0xF8) {
1585  goto end;
1586  }
1587  for (i = (value2 / 8) + 1; i < (256 / 8); i++) {
1588  if (sig->init_data->proto.proto[i] != 0xFF)
1589  goto end;
1590  }
1591 
1592  result = 1;
1593 
1594  end:
1595  SigFree(NULL, sig);
1596  return result;
1597 }
1598 
1599 static int DetectIPProtoTestSetup76(void)
1600 {
1601  int result = 0;
1602  Signature *sig;
1603  const char *value1_str = "!8";
1604  const char *value2_str = ">10";
1605  int value2 = 10;
1606  int i;
1607 
1608  if ((sig = SigAlloc()) == NULL)
1609  goto end;
1610 
1613  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1614  goto end;
1615  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
1616  goto end;
1617  for (i = 0; i < (value2 / 8); i++) {
1618  if (sig->init_data->proto.proto[i] != 0)
1619  goto end;
1620  }
1621  if (sig->init_data->proto.proto[value2 / 8] != 0xF8) {
1622  goto end;
1623  }
1624  for (i = (value2 / 8) + 1; i < (256 / 8); i++) {
1625  if (sig->init_data->proto.proto[i] != 0xFF)
1626  goto end;
1627  }
1628 
1629  result = 1;
1630 
1631  end:
1632  SigFree(NULL, sig);
1633  return result;
1634 }
1635 
1636 static int DetectIPProtoTestSetup129(void)
1637 {
1638  int result = 0;
1639  Signature *sig;
1640  const char *value1_str = "<10";
1641  int value1 = 10;
1642  const char *value2_str = ">10";
1643  int i;
1644 
1645  if ((sig = SigAlloc()) == NULL)
1646  goto end;
1647 
1650  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
1651  goto end;
1652  for (i = 0; i < (value1 / 8); i++) {
1653  if (sig->init_data->proto.proto[i] != 0xFF)
1654  goto end;
1655  }
1656  if (sig->init_data->proto.proto[value1 / 8] != 0x03) {
1657  goto end;
1658  }
1659  for (i = (value1 / 8) + 1; i < 256 / 8; i++) {
1660  if (sig->init_data->proto.proto[i] != 0)
1661  goto end;
1662  }
1663  if (DetectIPProtoSetup(NULL, sig, value2_str) == 0)
1664  goto end;
1665 
1666  result = 1;
1667 
1668  end:
1669  SigFree(NULL, sig);
1670  return result;
1671 }
1672 
1673 static int DetectIPProtoTestSetup130(void)
1674 {
1675  int result = 0;
1676  Signature *sig;
1677  const char *value1_str = "<10";
1678  const char *value2_str = ">10";
1679  int value2 = 10;
1680  int i;
1681 
1682  if ((sig = SigAlloc()) == NULL)
1683  goto end;
1684 
1687  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1688  goto end;
1689  if (DetectIPProtoSetup(NULL, sig, value1_str) == 0)
1690  goto end;
1691  for (i = 0; i < (value2 / 8); i++) {
1692  if (sig->init_data->proto.proto[i] != 0)
1693  goto end;
1694  }
1695  if (sig->init_data->proto.proto[value2 / 8] != 0xF8) {
1696  goto end;
1697  }
1698  for (i = (value2 / 8) + 1; i < 256 / 8; i++) {
1699  if (sig->init_data->proto.proto[i] != 0xFF)
1700  goto end;
1701  }
1702 
1703  result = 1;
1704 
1705  end:
1706  SigFree(NULL, sig);
1707  return result;
1708 }
1709 
1710 static int DetectIPProtoTestSetup131(void)
1711 {
1712  int result = 0;
1713  Signature *sig;
1714  const char *value1_str = "<10";
1715  int value1 = 10;
1716  const char *value2_str = "!10";
1717  int i;
1718 
1719  if ((sig = SigAlloc()) == NULL)
1720  goto end;
1721 
1724  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
1725  goto end;
1726  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1727  goto end;
1728  for (i = 0; i < (value1 / 8); i++) {
1729  if (sig->init_data->proto.proto[i] != 0xFF)
1730  goto end;
1731  }
1732  if (sig->init_data->proto.proto[value1 / 8] != 0x03) {
1733  goto end;
1734  }
1735  for (i = (value1 / 8) + 1; i < 256 / 8; i++) {
1736  if (sig->init_data->proto.proto[i] != 0x0)
1737  goto end;
1738  }
1739 
1740  result = 1;
1741 
1742  end:
1743  SigFree(NULL, sig);
1744  return result;
1745 }
1746 
1747 static int DetectIPProtoTestSetup132(void)
1748 {
1749  int result = 0;
1750  Signature *sig;
1751  const char *value1_str = "<10";
1752  int value1 = 10;
1753  const char *value2_str = "!10";
1754  int i;
1755 
1756  if ((sig = SigAlloc()) == NULL)
1757  goto end;
1758 
1761  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1762  goto end;
1763  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
1764  goto end;
1765  for (i = 0; i < (value1 / 8); i++) {
1766  if (sig->init_data->proto.proto[i] != 0xFF)
1767  goto end;
1768  }
1769  if (sig->init_data->proto.proto[value1 / 8] != 0x03) {
1770  goto end;
1771  }
1772  for (i = (value1 / 8) + 1; i < 256 / 8; i++) {
1773  if (sig->init_data->proto.proto[i] != 0x0)
1774  goto end;
1775  }
1776 
1777  result = 1;
1778 
1779  end:
1780  SigFree(NULL, sig);
1781  return result;
1782 }
1783 
1784 static int DetectIPProtoTestSetup145(void)
1785 {
1786  int result = 0;
1787  Signature *sig;
1788  const char *value1_str = "!4";
1789  const char *value2_str = ">8";
1790  const char *value3_str = "!10";
1791  const char *value4_str = "!14";
1792  const char *value5_str = "!27";
1793  const char *value6_str = "!29";
1794  const char *value7_str = "!30";
1795  const char *value8_str = "!34";
1796  const char *value9_str = "<36";
1797  const char *value10_str = "!38";
1798  int value10 = 38;
1799 
1800  int i;
1801 
1802  if ((sig = SigAlloc()) == NULL)
1803  goto end;
1804 
1807  if (DetectIPProtoSetup(NULL, sig, value5_str) != 0)
1808  goto end;
1809  if (DetectIPProtoSetup(NULL, sig, value8_str) != 0)
1810  goto end;
1811  if (DetectIPProtoSetup(NULL, sig, value2_str) != 0)
1812  goto end;
1813  if (DetectIPProtoSetup(NULL, sig, value10_str) != 0)
1814  goto end;
1815  if (DetectIPProtoSetup(NULL, sig, value1_str) != 0)
1816  goto end;
1817  if (DetectIPProtoSetup(NULL, sig, value6_str) != 0)
1818  goto end;
1819  if (DetectIPProtoSetup(NULL, sig, value9_str) != 0)
1820  goto end;
1821  if (DetectIPProtoSetup(NULL, sig, value4_str) != 0)
1822  goto end;
1823  if (DetectIPProtoSetup(NULL, sig, value3_str) != 0)
1824  goto end;
1825  if (DetectIPProtoSetup(NULL, sig, value7_str) != 0)
1826  goto end;
1827  if (sig->init_data->proto.proto[0] != 0) {
1828  goto end;
1829  }
1830  if (sig->init_data->proto.proto[1] != 0xBA) {
1831  goto end;
1832  }
1833  if (sig->init_data->proto.proto[2] != 0xFF) {
1834  goto end;
1835  }
1836  if (sig->init_data->proto.proto[3] != 0x97) {
1837  goto end;
1838  }
1839  if (sig->init_data->proto.proto[4] != 0x0B) {
1840  goto end;
1841  }
1842  for (i = (value10 / 8) + 1; i < 256 / 8; i++) {
1843  if (sig->init_data->proto.proto[i] != 0)
1844  goto end;
1845  }
1846 
1847  result = 1;
1848 
1849  end:
1850  SigFree(NULL, sig);
1851  return result;
1852 }
1853 
1854 static int DetectIPProtoTestSig1(void)
1855 {
1856  int result = 0;
1857  uint8_t *buf = (uint8_t *)
1858  "GET /one/ HTTP/1.1\r\n"
1859  "Host: one.example.org\r\n"
1860  "\r\n";
1861  uint16_t buflen = strlen((char *)buf);
1862  Packet *p = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_TCP);
1863  if (p == NULL)
1864  return 0;
1865 
1866  const char *sigs[4];
1867  sigs[0] = "alert ip any any -> any any "
1868  "(msg:\"Not tcp\"; ip_proto:!tcp; content:\"GET \"; sid:1;)";
1869  sigs[1] = "alert ip any any -> any any "
1870  "(msg:\"Less than 7\"; content:\"GET \"; ip_proto:<7; sid:2;)";
1871  sigs[2] = "alert ip any any -> any any "
1872  "(msg:\"Greater than 5\"; content:\"GET \"; ip_proto:>5; sid:3;)";
1873  sigs[3] = "alert ip any any -> any any "
1874  "(msg:\"Equals tcp\"; content:\"GET \"; ip_proto:tcp; sid:4;)";
1875 
1876  /* sids to match */
1877  uint32_t sid[4] = {1, 2, 3, 4};
1878  /* expected matches for each sid within this packet we are testing */
1879  uint32_t results[4] = {0, 1, 1, 1};
1880 
1881  /* remember that UTHGenericTest expect the first parameter
1882  * as an array of packet pointers. And also a bidimensional array of results
1883  * For example:
1884  * results[numpacket][position] should hold the number of times
1885  * that the sid at sid[position] matched that packet (should be always 1..)
1886  * But here we built it as unidimensional array
1887  */
1888  result = UTHGenericTest(&p, 1, sigs, sid, results, 4);
1889 
1890  UTHFreePacket(p);
1891  return result;
1892 }
1893 
1894 static int DetectIPProtoTestSig2(void)
1895 {
1896  uint8_t raw_eth[] = {
1897  0x01, 0x00, 0x5e, 0x00, 0x00, 0x0d, 0x00, 0x26,
1898  0x88, 0x61, 0x3a, 0x80, 0x08, 0x00, 0x45, 0xc0,
1899  0x00, 0x36, 0xe4, 0xcd, 0x00, 0x00, 0x01, 0x67,
1900  0xc7, 0xab, 0xac, 0x1c, 0x7f, 0xfe, 0xe0, 0x00,
1901  0x00, 0x0d, 0x20, 0x00, 0x90, 0x20, 0x00, 0x01,
1902  0x00, 0x02, 0x00, 0x69, 0x00, 0x02, 0x00, 0x04,
1903  0x81, 0xf4, 0x07, 0xd0, 0x00, 0x13, 0x00, 0x04,
1904  0x00, 0x00, 0x00, 0x01, 0x00, 0x14, 0x00, 0x04,
1905  0x4a, 0xea, 0x7a, 0x8e,
1906  };
1907 
1909  FAIL_IF_NULL(p);
1910 
1912  ThreadVars th_v;
1913  DetectEngineThreadCtx *det_ctx = NULL;
1914 
1915  p->proto = 0;
1916  memset(&dtv, 0, sizeof(DecodeThreadVars));
1917  memset(&th_v, 0, sizeof(th_v));
1919 
1921  DecodeEthernet(&th_v, &dtv, p, raw_eth, sizeof(raw_eth));
1922 
1926  de_ctx->flags |= DE_QUIET;
1927 
1929  "alert ip any any -> any any (msg:\"Check ipproto usage\"; "
1930  "ip_proto:!103; sid:1;)");
1931  FAIL_IF_NULL(s);
1932 
1934  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1935 
1936  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1937  FAIL_IF(PacketAlertCheck(p, 1));
1938 
1939  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1941  PacketFree(p);
1942  FlowShutdown();
1944  PASS;
1945 }
1946 
1947 static int DetectIPProtoTestSig3(void)
1948 {
1949  uint8_t raw_eth[] = {
1950  0x01, 0x00, 0x5e, 0x00, 0x00, 0x0d, 0x00, 0x26,
1951  0x88, 0x61, 0x3a, 0x80, 0x08, 0x00, 0x45, 0xc0,
1952  0x00, 0x36, 0xe4, 0xcd, 0x00, 0x00, 0x01, 0x67,
1953  0xc7, 0xab, 0xac, 0x1c, 0x7f, 0xfe, 0xe0, 0x00,
1954  0x00, 0x0d, 0x20, 0x00, 0x90, 0x20, 0x00, 0x01,
1955  0x00, 0x02, 0x00, 0x69, 0x00, 0x02, 0x00, 0x04,
1956  0x81, 0xf4, 0x07, 0xd0, 0x00, 0x13, 0x00, 0x04,
1957  0x00, 0x00, 0x00, 0x01, 0x00, 0x14, 0x00, 0x04,
1958  0x4a, 0xea, 0x7a, 0x8e,
1959  };
1960 
1962  FAIL_IF_NULL(p);
1963 
1965  ThreadVars th_v;
1966  DetectEngineThreadCtx *det_ctx = NULL;
1967 
1968  p->proto = 0;
1969  memset(&dtv, 0, sizeof(DecodeThreadVars));
1970  memset(&th_v, 0, sizeof(th_v));
1972 
1974  DecodeEthernet(&th_v, &dtv, p, raw_eth, sizeof(raw_eth));
1975 
1977  FAIL_IF(de_ctx == NULL);
1979  de_ctx->flags |= DE_QUIET;
1980 
1982  "alert ip any any -> any any (msg:\"Check ipproto usage\"; "
1983  "ip_proto:103; sid:1;)");
1984  FAIL_IF_NULL(s);
1985 
1987  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1988 
1989  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1990  FAIL_IF(!PacketAlertCheck(p, 1));
1991  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1993  FlowShutdown();
1994 
1995  PacketFree(p);
1997  PASS;
1998 }
1999 
2000 /**
2001  * \internal
2002  * \brief Register ip_proto tests.
2003  */
2004 static void DetectIPProtoRegisterTests(void)
2005 {
2006  UtRegisterTest("DetectIPProtoTestParse01", DetectIPProtoTestParse01);
2007  UtRegisterTest("DetectIPProtoTestParse02", DetectIPProtoTestParse02);
2008  UtRegisterTest("DetectIPProtoTestSetup01", DetectIPProtoTestSetup01);
2009  UtRegisterTest("DetectIPProtoTestSetup02", DetectIPProtoTestSetup02);
2010  UtRegisterTest("DetectIPProtoTestSetup03", DetectIPProtoTestSetup03);
2011  UtRegisterTest("DetectIPProtoTestSetup04", DetectIPProtoTestSetup04);
2012  UtRegisterTest("DetectIPProtoTestSetup05", DetectIPProtoTestSetup05);
2013  UtRegisterTest("DetectIPProtoTestSetup06", DetectIPProtoTestSetup06);
2014  UtRegisterTest("DetectIPProtoTestSetup07", DetectIPProtoTestSetup07);
2015  UtRegisterTest("DetectIPProtoTestSetup08", DetectIPProtoTestSetup08);
2016  UtRegisterTest("DetectIPProtoTestSetup09", DetectIPProtoTestSetup09);
2017  UtRegisterTest("DetectIPProtoTestSetup10", DetectIPProtoTestSetup10);
2018  UtRegisterTest("DetectIPProtoTestSetup11", DetectIPProtoTestSetup11);
2019  UtRegisterTest("DetectIPProtoTestSetup12", DetectIPProtoTestSetup12);
2020  UtRegisterTest("DetectIPProtoTestSetup13", DetectIPProtoTestSetup13);
2021  UtRegisterTest("DetectIPProtoTestSetup14", DetectIPProtoTestSetup14);
2022  UtRegisterTest("DetectIPProtoTestSetup15", DetectIPProtoTestSetup15);
2023  UtRegisterTest("DetectIPProtoTestSetup16", DetectIPProtoTestSetup16);
2024  UtRegisterTest("DetectIPProtoTestSetup17", DetectIPProtoTestSetup17);
2025  UtRegisterTest("DetectIPProtoTestSetup18", DetectIPProtoTestSetup18);
2026  UtRegisterTest("DetectIPProtoTestSetup19", DetectIPProtoTestSetup19);
2027  UtRegisterTest("DetectIPProtoTestSetup20", DetectIPProtoTestSetup20);
2028  UtRegisterTest("DetectIPProtoTestSetup21", DetectIPProtoTestSetup21);
2029  UtRegisterTest("DetectIPProtoTestSetup22", DetectIPProtoTestSetup22);
2030  UtRegisterTest("DetectIPProtoTestSetup23", DetectIPProtoTestSetup23);
2031  UtRegisterTest("DetectIPProtoTestSetup24", DetectIPProtoTestSetup24);
2032  UtRegisterTest("DetectIPProtoTestSetup33", DetectIPProtoTestSetup33);
2033  UtRegisterTest("DetectIPProtoTestSetup34", DetectIPProtoTestSetup34);
2034  UtRegisterTest("DetectIPProtoTestSetup36", DetectIPProtoTestSetup36);
2035  UtRegisterTest("DetectIPProtoTestSetup43", DetectIPProtoTestSetup43);
2036  UtRegisterTest("DetectIPProtoTestSetup44", DetectIPProtoTestSetup44);
2037  UtRegisterTest("DetectIPProtoTestSetup45", DetectIPProtoTestSetup45);
2038  UtRegisterTest("DetectIPProtoTestSetup56", DetectIPProtoTestSetup56);
2039  UtRegisterTest("DetectIPProtoTestSetup75", DetectIPProtoTestSetup75);
2040  UtRegisterTest("DetectIPProtoTestSetup76", DetectIPProtoTestSetup76);
2041  UtRegisterTest("DetectIPProtoTestSetup129", DetectIPProtoTestSetup129);
2042  UtRegisterTest("DetectIPProtoTestSetup130", DetectIPProtoTestSetup130);
2043  UtRegisterTest("DetectIPProtoTestSetup131", DetectIPProtoTestSetup131);
2044  UtRegisterTest("DetectIPProtoTestSetup132", DetectIPProtoTestSetup132);
2045  UtRegisterTest("DetectIPProtoTestSetup145", DetectIPProtoTestSetup145);
2046 
2047  UtRegisterTest("DetectIPProtoTestSig1", DetectIPProtoTestSig1);
2048  UtRegisterTest("DetectIPProtoTestSig2", DetectIPProtoTestSig2);
2049  UtRegisterTest("DetectIPProtoTestSig3", DetectIPProtoTestSig3);
2050 }
2051 #endif /* UNITTESTS */
DetectIPProtoRemoveAllSMs
void DetectIPProtoRemoveAllSMs(DetectEngineCtx *de_ctx, Signature *s)
Definition: detect-ipproto.c:427
util-byte.h
SigTableElmt_::url
const char * url
Definition: detect.h:1548
Packet_::proto
uint8_t proto
Definition: decode.h:550
detect-engine.h
SigMatchRemoveSMFromList
void SigMatchRemoveSMFromList(Signature *s, SigMatch *sm, int sm_list)
Definition: detect-parse.c:523
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:637
SigTableElmt_::desc
const char * desc
Definition: detect.h:1547
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:78
SigMatchFree
void SigMatchFree(DetectEngineCtx *de_ctx, SigMatch *sm)
free a SigMatch
Definition: detect-parse.c:325
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1532
DETECT_PROTO_IPV6
#define DETECT_PROTO_IPV6
Definition: detect-engine-proto.h:32
detect-engine-siggroup.h
DetectParseRegex
Definition: detect-parse.h:98
SigTableElmt_::name
const char * name
Definition: detect.h:1545
SCSigMatchGetCtx
const SigMatchCtx * SCSigMatchGetCtx(const SigMatch *sm)
Get the keyword context of sm, as passed to SCSigMatchAppendSMToList() by the keyword's Setup callbac...
Definition: detect-parse.c:786
SigFree
void SigFree(DetectEngineCtx *, Signature *)
Definition: detect-parse.c:2434
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:101
SigTableElmt_::flags
uint32_t flags
Definition: detect.h:1536
DetectIPProtoRegister
void DetectIPProtoRegister(void)
Registration function for ip_proto keyword.
Definition: detect-ipproto.c:59
PacketAlertCheck
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
Definition: detect-engine-alert.c:144
SIGMATCH_QUOTES_OPTIONAL
#define SIGMATCH_QUOTES_OPTIONAL
Definition: detect-engine-register.h:347
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:966
DETECT_PROTO_ANY
#define DETECT_PROTO_ANY
Definition: detect-engine-proto.h:28
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2913
DE_QUIET
#define DE_QUIET
Definition: detect.h:305
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
mpm_default_matcher
uint8_t mpm_default_matcher
Definition: util-mpm.c:47
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:3360
p
Packet * p
Definition: fuzz_dataset.c:30
SignatureInitData_::init_flags
uint32_t init_flags
Definition: detect.h:596
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
Definition: detect-parse.c:4099
proto
uint8_t proto
Definition: decode-template.h:0
StringParseInt32
int StringParseInt32(int32_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:586
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:4045
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1527
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
FlowInitConfig
void FlowInitConfig(bool quiet)
initialize the configuration
Definition: flow.c:574
StringParseUint8
int StringParseUint8(uint8_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:322
decode.h
util-debug.h
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:22
DetectEngineThreadCtx_
Definition: detect.h:1295
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:4225
detect-engine-mpm.h
SCSigMatchAppendSMToList
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:424
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
Definition: detect-engine.c:3666
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:335
DetectEngineCtx_::mpm_matcher
uint8_t mpm_matcher
Definition: detect.h:969
PacketFree
void PacketFree(Packet *p)
Return a malloced packet.
Definition: decode.c:231
SignatureInitData_::proto
DetectProto proto
Definition: detect.h:626
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:334
DetectProto_::proto
uint8_t proto[256/8]
Definition: detect-engine-proto.h:39
Signature_::flags
uint32_t flags
Definition: detect.h:664
Packet_
Definition: decode.h:528
detect-engine-build.h
detect-engine-alert.h
detect-ipproto.h
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:746
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1507
DETECT_IPPROTO_OP_GT
#define DETECT_IPPROTO_OP_GT
Definition: detect-ipproto.h:31
util-proto-name.h
SIG_FLAG_INIT_FIRST_IPPROTO_SEEN
#define SIG_FLAG_INIT_FIRST_IPPROTO_SEEN
Definition: detect.h:268
DETECT_IPPROTO_OP_EQ
#define DETECT_IPPROTO_OP_EQ
Definition: detect-ipproto.h:28
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:2300
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:35
StatsThreadInit
void StatsThreadInit(StatsThreadContext *stats)
Definition: counters.c:1332
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:326
SCDetectSignatureGetLastSMByType
const SigMatch * SCDetectSignatureGetLastSMByType(const Signature *s, int list_id, uint16_t type)
Get the last SigMatch of keyword type in list list_id.
Definition: detect-parse.c:758
DetectProto_::flags
uint8_t flags
Definition: detect-engine-proto.h:40
th_v
ThreadVars * th_v
Definition: fuzz_dataset.c:29
DETECT_PROTO_IPV4
#define DETECT_PROTO_IPV4
Definition: detect-engine-proto.h:31
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
suricata-common.h
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect-engine-register.h:306
SigMatch_::type
uint16_t type
Definition: detect.h:332
DETECT_IPPROTO_OP_LT
#define DETECT_IPPROTO_OP_LT
Definition: detect-ipproto.h:30
FlowShutdown
void FlowShutdown(void)
shutdown the flow engine
Definition: flow.c:718
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
Definition: detect-engine.c:3944
SCSigMatchGetPrevByType
const SigMatch * SCSigMatchGetPrevByType(const SigMatch *sm, uint16_t type)
Get the previous SigMatch of keyword type before sm.
Definition: detect-parse.c:775
DetectIPProtoData_::op
uint8_t op
Definition: detect-ipproto.h:35
UTHGenericTest
int UTHGenericTest(Packet **pkt, int numpkts, const char *sigs[], uint32_t sids[], uint32_t *results, int numsigs)
UTHGenericTest: function that perform a generic check taking care of as maximum common unittest eleme...
Definition: util-unittest-helper.c:578
PacketGetFromAlloc
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
Definition: decode.c:270
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:274
SCFree
#define SCFree(p)
Definition: util-mem.h:61
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:1015
UTHFreePacket
void UTHFreePacket(Packet *p)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:470
detect-parse.h
Signature_
Signature container.
Definition: detect.h:663
SigMatch_
a single match condition for a signature
Definition: detect.h:331
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2874
DetectIPProtoData_
Definition: detect-ipproto.h:34
FLOW_QUIET
#define FLOW_QUIET
Definition: flow.h:43
SCGetProtoByName
bool SCGetProtoByName(const char *protoname, uint8_t *proto_number)
Function to return the protocol number for a named protocol. Note that protocol name aliases are hono...
Definition: util-proto-name.c:462
PARSE_REGEX
#define PARSE_REGEX
Regex for parsing our options.
Definition: detect-ipproto.c:49
DETECT_IPPROTO_OP_NOT
#define DETECT_IPPROTO_OP_NOT
Definition: detect-ipproto.h:29
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:968
SigAlloc
Signature * SigAlloc(void)
Definition: detect-parse.c:2314
DETECT_IPPROTO
@ DETECT_IPPROTO
Definition: detect-engine-register.h:114
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
ThreadVars_::stats
StatsThreadContext stats
Definition: threadvars.h:120
StatsThreadCleanup
void StatsThreadCleanup(StatsThreadContext *stats)
Definition: counters.c:1428
DecodeEthernet
int DecodeEthernet(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Definition: decode-ethernet.c:41
detect-engine-address.h
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1534
DetectIPProtoData_::proto
uint8_t proto
Definition: detect-ipproto.h:36
SIG_FLAG_REQUIRE_PACKET
#define SIG_FLAG_REQUIRE_PACKET
Definition: detect.h:228