63 static FILE *g_ut_threshold_fp = NULL;
67 #define DETECT_BASE_REGEX "^\\s*(event_filter|threshold|rate_filter|suppress)\\s*gen_id\\s*(\\d+)\\s*,\\s*sig_id\\s*(\\d+)\\s*(.*)\\s*$"
69 #define DETECT_THRESHOLD_REGEX \
70 "^,\\s*type\\s*(limit|both|threshold)\\s*,\\s*track\\s*(by_dst|by_src|by_both|by_rule)\\s*," \
71 "\\s*count\\s*(\\d+)\\s*,\\s*seconds\\s*(\\d+)\\s*$"
74 #define DETECT_RATE_REGEX "^,\\s*track\\s*(by_dst|by_src|by_both|by_rule)\\s*,\\s*count\\s*(\\d+)\\s*,\\s*seconds\\s*(\\d+)\\s*,\\s*new_action\\s*(alert|drop|pass|log|sdrop|reject)\\s*,\\s*timeout\\s*(\\d+)\\s*$"
82 #define DETECT_SUPPRESS_REGEX "^,\\s*track\\s*(by_dst|by_src|by_either)\\s*,\\s*ip\\s*([\\[\\],\\$\\s\\da-zA-Z.:/_]+)*\\s*$"
85 #if defined OS_WIN32 || defined __CYGWIN__
86 #define THRESHOLD_CONF_DEF_CONF_FILEPATH CONFIG_DIR "\\\\threshold.config"
88 #define THRESHOLD_CONF_DEF_CONF_FILEPATH CONFIG_DIR "/threshold.config"
101 if (regex_base == NULL) {
102 FatalError(
"classification base regex setup failed");
105 if (regex_threshold == NULL) {
106 FatalError(
"classification threshold regex setup failed");
109 if (regex_rate == NULL) {
110 FatalError(
"classification rate_filter regex setup failed");
113 if (regex_suppress == NULL) {
114 FatalError(
"classification suppress regex setup failed");
129 const char *log_filename = NULL;
132 char config_value[256];
133 snprintf(config_value,
sizeof(config_value),
138 if (
ConfGet(config_value, &log_filename) != 1) {
139 if (
ConfGet(
"threshold-file", &log_filename) != 1) {
144 if (
ConfGet(
"threshold-file", &log_filename) != 1) {
167 const char *filename = NULL;
172 FILE *fd = g_ut_threshold_fp;
175 filename = SCThresholdConfGetConfFilename(
de_ctx);
176 if ( (fd = fopen(filename,
"r")) == NULL) {
177 SCLogWarning(
"Error opening file: \"%s\": %s", filename, strerror(errno));
178 SCThresholdConfDeInitContext(
de_ctx, fd);
186 SCLogWarning(
"Error loading threshold configuration from %s", filename);
187 SCThresholdConfDeInitContext(
de_ctx, fd);
194 SCThresholdConfDeInitContext(
de_ctx, fd);
197 g_ut_threshold_fp = NULL;
199 SCLogDebug(
"Global thresholding options defined");
222 uint8_t parsed_type, uint8_t parsed_track, uint32_t parsed_count,
223 uint32_t parsed_seconds, uint32_t parsed_timeout, uint8_t parsed_new_action,
239 orig_de->
track = parsed_track;
240 orig_de->
count = parsed_count;
241 orig_de->
seconds = parsed_seconds;
243 orig_de->
timeout = parsed_timeout;
252 if (
id == 0 && gid == 0) {
276 sm->
ctx = (
void *)
de;
279 }
else if (
id == 0 && gid > 0) {
281 SCLogWarning(
"suppressing all rules with gid %" PRIu32, gid);
305 sm->
ctx = (
void *)
de;
309 }
else if (
id > 0 && gid == 0) {
310 SCLogError(
"Can't use a event config that has "
311 "sid > 0 and gid == 0. Please fix this "
312 "in your threshold.config file");
318 "%" PRIu32
", gid %" PRIu32
": unknown rule",
337 sm->
ctx = (
void *)
de;
344 if (orig_de != NULL) {
350 if (orig_de != NULL) {
367 uint8_t parsed_type, uint8_t parsed_track, uint32_t parsed_count,
368 uint32_t parsed_seconds, uint32_t parsed_timeout, uint8_t parsed_new_action,
378 if (
id == 0 && gid == 0) {
384 "an event var set. The signature event var is "
385 "given precedence over the threshold.conf one. "
386 "We'll change this in the future though.",
395 "an event var set. The signature event var is "
396 "given precedence over the threshold.conf one. "
397 "We'll change this in the future though.",
407 de->type = parsed_type;
408 de->track = parsed_track;
409 de->count = parsed_count;
410 de->seconds = parsed_seconds;
411 de->new_action = parsed_new_action;
412 de->timeout = parsed_timeout;
424 sm->
ctx = (
void *)
de;
429 }
else if (
id == 0 && gid > 0) {
436 "an event var set. The signature event var is "
437 "given precedence over the threshold.conf one. "
438 "We'll change this in the future though.",
448 de->type = parsed_type;
449 de->track = parsed_track;
450 de->count = parsed_count;
451 de->seconds = parsed_seconds;
452 de->new_action = parsed_new_action;
453 de->timeout = parsed_timeout;
465 sm->
ctx = (
void *)
de;
470 }
else if (
id > 0 && gid == 0) {
471 SCLogError(
"Can't use a event config that has "
472 "sid > 0 and gid == 0. Please fix this "
473 "in your threshold.conf file");
478 "%" PRIu32
", gid %" PRIu32
": unknown rule",
488 "a threshold set. The signature event var is "
489 "given precedence over the threshold.conf one. "
499 "a detection_filter set. The signature event var is "
500 "given precedence over the threshold.conf one. "
522 de->type = parsed_type;
523 de->track = parsed_track;
524 de->count = parsed_count;
525 de->seconds = parsed_seconds;
526 de->new_action = parsed_new_action;
527 de->timeout = parsed_timeout;
539 sm->
ctx = (
void *)
de;
555 uint32_t *ret_gid, uint8_t *ret_parsed_type, uint8_t *ret_parsed_track,
556 uint32_t *ret_parsed_count, uint32_t *ret_parsed_seconds, uint32_t *ret_parsed_timeout,
557 uint8_t *ret_parsed_new_action,
char **ret_th_ip)
559 char th_rule_type[32];
562 const char *rule_extend = NULL;
563 char th_type[16] =
"";
564 char th_track[16] =
"";
565 char th_count[16] =
"";
566 char th_seconds[16] =
"";
567 char th_new_action[16] =
"";
568 char th_timeout[16] =
"";
569 const char *th_ip = NULL;
571 uint8_t parsed_type = 0;
572 uint8_t parsed_track = 0;
573 uint8_t parsed_new_action = 0;
574 uint32_t parsed_count = 0;
575 uint32_t parsed_seconds = 0;
576 uint32_t parsed_timeout = 0;
579 uint32_t
id = 0, gid = 0;
585 pcre2_match_data *regex_base_match = NULL;
588 SCLogError(
"pcre2_match parse error, ret %" PRId32
", string %s", ret, rawstr);
589 pcre2_match_data_free(regex_base_match);
594 size_t copylen =
sizeof(th_rule_type);
595 ret = pcre2_substring_copy_bynumber(
596 regex_base_match, 1, (PCRE2_UCHAR8 *)th_rule_type, ©len);
598 SCLogError(
"pcre2_substring_copy_bynumber failed");
599 pcre2_match_data_free(regex_base_match);
604 copylen =
sizeof(th_gid);
605 ret = pcre2_substring_copy_bynumber(regex_base_match, 2, (PCRE2_UCHAR8 *)th_gid, ©len);
607 SCLogError(
"pcre2_substring_copy_bynumber failed");
608 pcre2_match_data_free(regex_base_match);
612 copylen =
sizeof(th_sid);
613 ret = pcre2_substring_copy_bynumber(regex_base_match, 3, (PCRE2_UCHAR8 *)th_sid, ©len);
615 SCLogError(
"pcre2_substring_copy_bynumber failed");
616 pcre2_match_data_free(regex_base_match);
621 ret = pcre2_substring_get_bynumber(
622 regex_base_match, 4, (PCRE2_UCHAR8 **)&rule_extend, ©len);
624 SCLogError(
"pcre2_substring_get_bynumber failed");
625 pcre2_match_data_free(regex_base_match);
628 pcre2_match_data_free(regex_base_match);
629 regex_base_match = NULL;
632 if (strcasecmp(th_rule_type,
"event_filter") == 0) {
634 }
else if (strcasecmp(th_rule_type,
"threshold") == 0) {
636 }
else if (strcasecmp(th_rule_type,
"rate_filter") == 0) {
638 }
else if (strcasecmp(th_rule_type,
"suppress") == 0) {
641 SCLogError(
"rule type %s is unknown", th_rule_type);
649 if (strlen(rule_extend) > 0) {
650 pcre2_match_data *match = NULL;
654 SCLogError(
"pcre2_match parse error, ret %" PRId32
", string %s", ret,
656 pcre2_match_data_free(match);
660 copylen =
sizeof(th_type);
661 ret = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)th_type, ©len);
663 SCLogError(
"pcre2_substring_copy_bynumber failed");
664 pcre2_match_data_free(match);
668 copylen =
sizeof(th_track);
669 ret = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)th_track, ©len);
671 SCLogError(
"pcre2_substring_copy_bynumber failed");
672 pcre2_match_data_free(match);
676 copylen =
sizeof(th_count);
677 ret = pcre2_substring_copy_bynumber(match, 3, (PCRE2_UCHAR8 *)th_count, ©len);
679 SCLogError(
"pcre2_substring_copy_bynumber failed");
680 pcre2_match_data_free(match);
684 copylen =
sizeof(th_seconds);
685 ret = pcre2_substring_copy_bynumber(match, 4, (PCRE2_UCHAR8 *)th_seconds, ©len);
687 SCLogError(
"pcre2_substring_copy_bynumber failed");
688 pcre2_match_data_free(match);
691 pcre2_match_data_free(match);
693 if (strcasecmp(th_type,
"limit") == 0)
695 else if (strcasecmp(th_type,
"both") == 0)
697 else if (strcasecmp(th_type,
"threshold") == 0)
700 SCLogError(
"limit type not supported: %s", th_type);
709 if (strlen(rule_extend) > 0) {
710 pcre2_match_data *match = NULL;
713 SCLogError(
"pcre2_match parse error, ret %" PRId32
", string %s", ret,
715 pcre2_match_data_free(match);
719 copylen =
sizeof(th_seconds);
720 ret = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)th_track, ©len);
722 SCLogError(
"pcre2_substring_copy_bynumber failed");
723 pcre2_match_data_free(match);
727 ret = pcre2_substring_get_bynumber(match, 2, (PCRE2_UCHAR8 **)&th_ip, ©len);
729 SCLogError(
"pcre2_substring_get_bynumber failed");
730 pcre2_match_data_free(match);
733 pcre2_match_data_free(match);
740 if (strlen(rule_extend) > 0) {
741 pcre2_match_data *match = NULL;
744 SCLogError(
"pcre2_match parse error, ret %" PRId32
", string %s", ret,
746 pcre2_match_data_free(match);
750 copylen =
sizeof(th_track);
751 ret = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)th_track, ©len);
753 SCLogError(
"pcre2_substring_copy_bynumber failed");
754 pcre2_match_data_free(match);
758 copylen =
sizeof(th_count);
759 ret = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)th_count, ©len);
761 SCLogError(
"pcre2_substring_copy_bynumber failed");
762 pcre2_match_data_free(match);
766 copylen =
sizeof(th_seconds);
767 ret = pcre2_substring_copy_bynumber(match, 3, (PCRE2_UCHAR8 *)th_seconds, ©len);
769 SCLogError(
"pcre2_substring_copy_bynumber failed");
770 pcre2_match_data_free(match);
774 copylen =
sizeof(th_new_action);
775 ret = pcre2_substring_copy_bynumber(
776 match, 4, (PCRE2_UCHAR8 *)th_new_action, ©len);
778 SCLogError(
"pcre2_substring_copy_bynumber failed");
779 pcre2_match_data_free(match);
783 copylen =
sizeof(th_timeout);
784 ret = pcre2_substring_copy_bynumber(match, 5, (PCRE2_UCHAR8 *)th_timeout, ©len);
786 SCLogError(
"pcre2_substring_copy_bynumber failed");
787 pcre2_match_data_free(match);
790 pcre2_match_data_free(match);
794 if (
StringParseUint32(&parsed_timeout, 10,
sizeof(th_timeout), th_timeout) <= 0) {
799 if (strcasecmp(th_new_action,
"alert") == 0)
801 if (strcasecmp(th_new_action,
"drop") == 0)
803 if (strcasecmp(th_new_action,
"pass") == 0)
805 if (strcasecmp(th_new_action,
"reject") == 0)
807 if (strcasecmp(th_new_action,
"log") == 0) {
808 SCLogInfo(
"log action for rate_filter not supported yet");
811 if (strcasecmp(th_new_action,
"sdrop") == 0) {
812 SCLogInfo(
"sdrop action for rate_filter not supported yet");
828 if (strcasecmp(th_track,
"by_dst") == 0)
830 else if (strcasecmp(th_track,
"by_src") == 0)
832 else if (strcasecmp(th_track,
"by_both") == 0) {
835 else if (strcasecmp(th_track,
"by_rule") == 0)
838 SCLogError(
"Invalid track parameter %s in %s", th_track, rawstr);
845 if (parsed_count == 0) {
846 SCLogError(
"rate filter count should be > 0");
850 if (
StringParseUint32(&parsed_seconds, 10,
sizeof(th_seconds), th_seconds) <= 0) {
857 if (strcmp(
"", th_track) != 0) {
858 if (strcasecmp(th_track,
"by_dst") == 0)
860 else if (strcasecmp(th_track,
"by_src") == 0)
862 else if (strcasecmp(th_track,
"by_either") == 0) {
866 SCLogError(
"Invalid track parameter %s in %s", th_track, rule_extend);
883 *ret_parsed_type = parsed_type;
884 *ret_parsed_track = parsed_track;
885 *ret_parsed_new_action = parsed_new_action;
886 *ret_parsed_count = parsed_count;
887 *ret_parsed_seconds = parsed_seconds;
888 *ret_parsed_timeout = parsed_timeout;
891 *ret_th_ip = (
char *)th_ip;
893 pcre2_substring_free((PCRE2_UCHAR8 *)rule_extend);
897 if (rule_extend != NULL) {
898 pcre2_substring_free((PCRE2_UCHAR8 *)rule_extend);
901 pcre2_substring_free((PCRE2_UCHAR8 *)th_ip);
918 uint8_t parsed_type = 0;
919 uint8_t parsed_track = 0;
920 uint8_t parsed_new_action = 0;
921 uint32_t parsed_count = 0;
922 uint32_t parsed_seconds = 0;
923 uint32_t parsed_timeout = 0;
925 uint32_t
id = 0, gid = 0;
927 int r = ParseThresholdRule(
de_ctx, rawstr, &
id, &gid, &parsed_type, &parsed_track,
928 &parsed_count, &parsed_seconds, &parsed_timeout, &parsed_new_action, &th_ip);
933 r = SetupSuppressRule(
de_ctx,
id, gid, parsed_type, parsed_track,
934 parsed_count, parsed_seconds, parsed_timeout, parsed_new_action,
937 r = SetupThresholdRule(
de_ctx,
id, gid, parsed_type, parsed_track,
938 parsed_count, parsed_seconds, parsed_timeout, parsed_new_action,
945 pcre2_substring_free((PCRE2_UCHAR8 *)th_ip);
949 pcre2_substring_free((PCRE2_UCHAR8 *)th_ip);
965 static int SCThresholdConfIsLineBlankOrComment(
char *line)
967 while (*line !=
'\0') {
973 if (!isspace((
unsigned char)*line))
991 static int SCThresholdConfLineIsMultiline(
char *line)
995 int len = strlen(line);
997 while (line < rline +
len && *line !=
'\n') {
1000 flag = line - rline;
1002 if (!isspace((
unsigned char)*line))
1020 char line[8192] =
"";
1029 while (fgets(line + esc_pos, (
int)
sizeof(line) - esc_pos, fp) != NULL) {
1030 if (SCThresholdConfIsLineBlankOrComment(line)) {
1034 esc_pos = SCThresholdConfLineIsMultiline(line);
1036 if (SCThresholdConfAddThresholdtype(line,
de_ctx) < 0) {
1040 SCLogDebug(
"Adding threshold.config rule num %" PRIu32
"( %s )", rule_num, line);
1046 SCLogInfo(
"Threshold config parsed: %d rule(s) found", rule_num);
1060 static FILE *SCThresholdConfGenerateValidDummyFD01(
void)
1063 const char *buffer =
1064 "event_filter gen_id 1, sig_id 10, type limit, track by_src, count 1, seconds 60\n"
1065 "threshold gen_id 1, sig_id 100, type both, track by_dst, count 10, seconds 60\n"
1066 "event_filter gen_id 1, sig_id 1000, type threshold, track by_src, count 100, seconds 60\n";
1068 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1070 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1081 static FILE *SCThresholdConfGenerateInvalidDummyFD02(
void)
1084 const char *buffer =
1085 "event_filter gen_id 1, sig_id 1000, type invalid, track by_src, count 100, seconds 60\n";
1087 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1089 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1099 static FILE *SCThresholdConfGenerateValidDummyFD03(
void)
1102 const char *buffer =
1103 "event_filter gen_id 0, sig_id 0, type threshold, track by_src, count 100, seconds 60\n";
1105 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1107 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1118 static FILE *SCThresholdConfGenerateValidDummyFD04(
void)
1121 const char *buffer =
1122 "event_filter gen_id 1 \\\n, sig_id 10, type limit, track by_src, \\\ncount 1, seconds 60\n"
1123 "threshold gen_id 1, \\\nsig_id 100, type both\\\n, track by_dst, count 10, \\\n seconds 60\n"
1124 "event_filter gen_id 1, sig_id 1000, \\\ntype threshold, track \\\nby_src, count 100, seconds 60\n";
1126 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1128 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1138 static FILE *SCThresholdConfGenerateValidDummyFD05(
void)
1141 const char *buffer =
1142 "rate_filter gen_id 1, sig_id 10, track by_src, count 1, seconds 60, new_action drop, timeout 10\n"
1143 "rate_filter gen_id 1, sig_id 100, track by_dst, count 10, seconds 60, new_action pass, timeout 5\n"
1144 "rate_filter gen_id 1, sig_id 1000, track by_rule, count 100, seconds 60, new_action alert, timeout 30\n"
1145 "rate_filter gen_id 1, sig_id 10000, track by_both, count 1000, seconds 60, new_action reject, timeout 21\n";
1147 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1149 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1160 static FILE *SCThresholdConfGenerateValidDummyFD06(
void)
1163 const char *buffer =
1164 "rate_filter \\\ngen_id 1, sig_id 10, track by_src, count 1, seconds 60\\\n, new_action drop, timeout 10\n"
1165 "rate_filter gen_id 1, \\\nsig_id 100, track by_dst, \\\ncount 10, seconds 60, new_action pass, timeout 5\n"
1166 "rate_filter gen_id 1, sig_id 1000, \\\ntrack by_rule, count 100, seconds 60, new_action alert, timeout 30\n"
1167 "rate_filter gen_id 1, sig_id 10000, track by_both, count 1000, \\\nseconds 60, new_action reject, timeout 21\n";
1169 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1171 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1182 static FILE *SCThresholdConfGenerateValidDummyFD07(
void)
1185 const char *buffer =
1186 "rate_filter gen_id 1, sig_id 10, track by_src, count 3, seconds 3, new_action drop, timeout 10\n"
1187 "rate_filter gen_id 1, sig_id 11, track by_src, count 3, seconds 1, new_action drop, timeout 5\n";
1189 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1191 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1201 static FILE *SCThresholdConfGenerateValidDummyFD08(
void)
1204 const char *buffer =
1205 "rate_filter gen_id 1, sig_id 10, track by_rule, count 3, seconds 3, new_action drop, timeout 10\n";
1207 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1209 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1220 static FILE *SCThresholdConfGenerateValidDummyFD09(
void)
1223 const char *buffer =
1224 "event_filter gen_id 1 \\\n, sig_id 10, type limit, track by_src, \\\ncount 2, seconds 60\n"
1225 "threshold gen_id 1, \\\nsig_id 11, type threshold\\\n, track by_dst, count 3, \\\n seconds 60\n"
1226 "event_filter gen_id 1, sig_id 12, \\\ntype both, track \\\nby_src, count 2, seconds 60\n";
1228 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1230 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1241 static FILE *SCThresholdConfGenerateValidDummyFD10(
void)
1244 const char *buffer =
1245 "event_filter gen_id 1 \\\n, sig_id 10, type limit, track by_src, \\\ncount 5, seconds 2\n"
1246 "threshold gen_id 1, \\\nsig_id 11, type threshold\\\n, track by_dst, count 5, \\\n seconds 2\n"
1247 "event_filter gen_id 1, sig_id 12, \\\ntype both, track \\\nby_src, count 5, seconds 2\n";
1249 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1251 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1261 static FILE *SCThresholdConfGenerateValidDummyFD11(
void)
1264 const char *buffer =
1265 "suppress gen_id 1, sig_id 10000\n"
1266 "suppress gen_id 1, sig_id 1000, track by_src, ip 192.168.1.1\n";
1268 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1270 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1281 static int SCThresholdConfTest01(
void)
1288 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:10;)");
1292 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD01();
1314 static int SCThresholdConfTest02(
void)
1321 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:100;)");
1325 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD01();
1347 static int SCThresholdConfTest03(
void)
1354 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:1000;)");
1358 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD01();
1380 static int SCThresholdConfTest04(
void)
1387 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:1000;)");
1391 g_ut_threshold_fp = SCThresholdConfGenerateInvalidDummyFD02();
1409 static int SCThresholdConfTest05(
void)
1416 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:1;)");
1419 "alert tcp any any -> any 80 (msg:\"Threshold limit\"; gid:1; sid:10;)");
1423 "alert tcp any any -> any 80 (msg:\"Threshold limit\"; gid:1; sid:100;)");
1427 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD03();
1464 static int SCThresholdConfTest06(
void)
1471 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:10;)");
1475 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD04();
1497 static int SCThresholdConfTest07(
void)
1504 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:10;)");
1508 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD05();
1531 static int SCThresholdConfTest08(
void)
1538 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:10;)");
1542 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD06();
1564 static int SCThresholdConfTest09(
void)
1567 memset(&th_v, 0,
sizeof(th_v));
1581 "alert tcp any any -> any any (msg:\"ratefilter test\"; gid:1; sid:10;)");
1585 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD07();
1648 static int SCThresholdConfTest10(
void)
1656 "172.26.0.2",
"172.26.0.11");
1659 "172.26.0.1",
"172.26.0.10");
1663 memset(&th_v, 0,
sizeof(th_v));
1671 "alert tcp any any -> any any (msg:\"ratefilter test\"; gid:1; sid:10;)");
1675 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD08();
1738 static int SCThresholdConfTest11(
void)
1746 memset(&th_v, 0,
sizeof(th_v));
1754 "alert tcp any any -> any any (msg:\"event_filter test limit\"; gid:1; sid:10;)");
1757 "alert tcp any any -> any any (msg:\"event_filter test threshold\"; gid:1; sid:11;)");
1760 "alert tcp any any -> any any (msg:\"event_filter test both\"; gid:1; sid:12;)");
1764 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD09();
1843 static int SCThresholdConfTest12(
void)
1851 memset(&th_v, 0,
sizeof(th_v));
1859 "alert tcp any any -> any any (msg:\"event_filter test limit\"; gid:1; sid:10;)");
1862 "alert tcp any any -> any any (msg:\"event_filter test threshold\"; gid:1; sid:11;)");
1865 "alert tcp any any -> any any (msg:\"event_filter test both\"; gid:1; sid:12;)");
1869 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD10();
1948 static int SCThresholdConfTest13(
void)
1955 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:1000;)");
1959 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD11();
1981 static int SCThresholdConfTest14(
void)
1986 "192.168.0.100", 1234, 24);
1989 "192.168.0.100", 1234, 24);
1998 "alert tcp any any -> any any (msg:\"suppress test\"; gid:1; sid:10000;)");
2001 "alert tcp any any -> any any (msg:\"suppress test 2\"; gid:1; sid:10;)");
2004 "alert tcp any any -> any any (msg:\"suppress test 3\"; gid:1; sid:1000;)");
2008 memset(&th_v, 0,
sizeof(th_v));
2011 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD11();
2042 static int SCThresholdConfTest15(
void)
2047 "192.168.0.100", 1234, 24);
2051 memset(&th_v, 0,
sizeof(th_v));
2059 "drop tcp any any -> any any (msg:\"suppress test\"; content:\"lalala\"; gid:1; sid:10000;)");
2063 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD11();
2090 static int SCThresholdConfTest16(
void)
2095 "192.168.0.100", 1234, 24);
2099 memset(&th_v, 0,
sizeof(th_v));
2107 "drop tcp any any -> any any (msg:\"suppress test\"; gid:1; sid:1000;)");
2111 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD11();
2137 static int SCThresholdConfTest17(
void)
2142 "192.168.0.100", 1234, 24);
2146 memset(&th_v, 0,
sizeof(th_v));
2154 "drop tcp 192.168.0.10 any -> 192.168.0.100 any (msg:\"suppress test\"; gid:1; sid:10000;)");
2158 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD11();
2184 static FILE *SCThresholdConfGenerateInvalidDummyFD12(
void)
2187 const char *buffer =
2188 "suppress gen_id 1, sig_id 2200029, track by_dst, ip fe80::/16\n"
2189 "suppress gen_id 1, sig_id 2200029, track by_stc, ip fe80::/16\n";
2191 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
2193 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
2204 static int SCThresholdConfTest18(
void)
2212 "alert tcp 192.168.0.10 any -> 192.168.0.100 any (msg:\"suppress test\"; gid:1; sid:2200029;)");
2215 g_ut_threshold_fp = SCThresholdConfGenerateInvalidDummyFD12();
2236 static FILE *SCThresholdConfGenerateInvalidDummyFD13(
void)
2239 const char *buffer =
2240 "suppress gen_id 1, sig_id 2200029, track by_stc, ip fe80::/16\n"
2241 "suppress gen_id 1, sig_id 2200029, track by_dst, ip fe80::/16\n";
2243 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
2245 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
2256 static int SCThresholdConfTest19(
void)
2263 "alert tcp 192.168.0.10 any -> 192.168.0.100 any (msg:\"suppress test\"; gid:1; sid:2200029;)");
2266 g_ut_threshold_fp = SCThresholdConfGenerateInvalidDummyFD13();
2285 static FILE *SCThresholdConfGenerateValidDummyFD20(
void)
2288 const char *buffer =
2289 "suppress gen_id 1, sig_id 1000, track by_src, ip 2.2.3.4\n"
2290 "suppress gen_id 1, sig_id 1000, track by_src, ip 1.2.3.4\n"
2291 "suppress gen_id 1, sig_id 1000, track by_src, ip 192.168.1.1\n";
2293 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
2295 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
2306 static int SCThresholdConfTest20(
void)
2313 "alert tcp any any -> any any (msg:\"Threshold limit\"; content:\"abc\"; sid:1000;)");
2316 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD20();
2352 static int SCThresholdConfTest21(
void)
2359 "alert tcp any any -> any any (msg:\"Threshold limit\"; content:\"abc\"; threshold: type limit, track by_dst, count 5, seconds 60; sid:1000;)");
2361 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD20();
2395 static FILE *SCThresholdConfGenerateValidDummyFD22(
void)
2398 const char *buffer =
2399 "rate_filter gen_id 1, sig_id 10, track by_both, count 2, seconds 5, new_action drop, timeout 6\n";
2401 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
2403 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
2414 static int SCThresholdConfTest22(
void)
2417 memset(&th_v, 0,
sizeof(th_v));
2440 "alert tcp any any -> any any (msg:\"ratefilter by_both test\"; gid:1; sid:10;)");
2444 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD22();
2452 p2->
ts = p3->
ts = p1->
ts;
2471 p2->
ts = p3->
ts = p1->
ts;
2482 p2->
ts = p3->
ts = p1->
ts;
2501 p2->
ts = p3->
ts = p1->
ts;
2531 static FILE *SCThresholdConfGenerateValidDummyFD23(
void)
2534 const char *buffer =
2535 "rate_filter gen_id 1, sig_id 10, track by_both, count 1, seconds 5, new_action drop, timeout 6\n";
2537 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
2539 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
2551 static int SCThresholdConfTest23(
void)
2554 memset(&th_v, 0,
sizeof(th_v));
2572 "alert tcp any any -> any any (msg:\"ratefilter by_both test\"; gid:1; sid:10;)");
2576 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD23();
2623 SCThresholdConfTest09);
2625 SCThresholdConfTest10);
2627 SCThresholdConfTest11);
2629 SCThresholdConfTest12);
2631 UtRegisterTest(
"SCThresholdConfTest14 - suppress", SCThresholdConfTest14);
2633 SCThresholdConfTest15);
2635 SCThresholdConfTest16);
2637 SCThresholdConfTest17);
2640 SCThresholdConfTest18);
2642 SCThresholdConfTest19);
2644 SCThresholdConfTest20);
2646 SCThresholdConfTest21);
2648 SCThresholdConfTest22);
2649 UtRegisterTest(
"SCThresholdConfTest23 - rate_filter by_both opposite",
2650 SCThresholdConfTest23);