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|by_" \
72 "\\s*count\\s*(\\d+)\\s*,\\s*seconds\\s*(\\d+)\\s*$"
75 #define DETECT_RATE_REGEX \
76 "^,\\s*track\\s*(by_dst|by_src|by_both|by_rule|by_flow)\\s*,\\s*count\\s*(\\d+)\\s*,\\s*" \
77 "seconds\\s*(\\d+)\\s*,\\s*new_action\\s*(alert|drop|pass|log|sdrop|reject)\\s*,\\s*" \
78 "timeout\\s*(\\d+)\\s*$"
86 #define DETECT_SUPPRESS_REGEX "^,\\s*track\\s*(by_dst|by_src|by_either)\\s*,\\s*ip\\s*([\\[\\],\\$\\s\\da-zA-Z.:/_]+)*\\s*$"
89 #if defined OS_WIN32 || defined __CYGWIN__
90 #define THRESHOLD_CONF_DEF_CONF_FILEPATH CONFIG_DIR "\\\\threshold.config"
92 #define THRESHOLD_CONF_DEF_CONF_FILEPATH CONFIG_DIR "/threshold.config"
105 if (regex_base == NULL) {
106 FatalError(
"classification base regex setup failed");
109 if (regex_threshold == NULL) {
110 FatalError(
"classification threshold regex setup failed");
113 if (regex_rate == NULL) {
114 FatalError(
"classification rate_filter regex setup failed");
117 if (regex_suppress == NULL) {
118 FatalError(
"classification suppress regex setup failed");
133 const char *log_filename = NULL;
136 char config_value[256];
137 snprintf(config_value,
sizeof(config_value),
142 if (
SCConfGet(config_value, &log_filename) != 1) {
143 if (
SCConfGet(
"threshold-file", &log_filename) != 1) {
148 if (
SCConfGet(
"threshold-file", &log_filename) != 1) {
171 const char *filename = NULL;
177 FILE *fd = g_ut_threshold_fp;
180 filename = SCThresholdConfGetConfFilename(
de_ctx);
181 if ( (fd = fopen(filename,
"r")) == NULL) {
182 SCLogWarning(
"Error opening file: \"%s\": %s", filename, strerror(errno));
183 SCThresholdConfDeInitContext(
de_ctx, fd);
192 SCLogWarning(
"Error loading threshold configuration from %s", filename);
193 SCThresholdConfDeInitContext(
de_ctx, fd);
200 SCThresholdConfDeInitContext(
de_ctx, fd);
203 g_ut_threshold_fp = NULL;
205 SCLogDebug(
"Global thresholding options defined");
227 uint8_t parsed_type, uint8_t parsed_track, uint32_t parsed_count,
228 uint32_t parsed_seconds, uint32_t parsed_timeout, uint8_t parsed_new_action,
243 orig_de->
track = parsed_track;
244 orig_de->
count = parsed_count;
245 orig_de->
seconds = parsed_seconds;
247 orig_de->
timeout = parsed_timeout;
256 if (
id == 0 && gid == 0) {
278 }
else if (
id == 0 && gid > 0) {
280 SCLogWarning(
"suppressing all rules with gid %" PRIu32, gid);
302 }
else if (
id > 0 && gid == 0) {
303 SCLogError(
"Can't use a event config that has "
304 "sid > 0 and gid == 0. Please fix this "
305 "in your threshold.config file");
311 "%" PRIu32
", gid %" PRIu32
": unknown rule",
331 if (orig_de != NULL) {
337 if (orig_de != NULL) {
354 uint8_t parsed_type, uint8_t parsed_track, uint32_t parsed_count, uint32_t parsed_seconds,
355 uint32_t parsed_timeout, uint8_t parsed_new_action)
364 if (
id == 0 && gid == 0) {
369 "an event var set. The signature event var is "
370 "given precedence over the threshold.conf one. "
371 "We'll change this in the future though.",
380 "an event var set. The signature event var is "
381 "given precedence over the threshold.conf one. "
382 "We'll change this in the future though.",
391 de->
type = parsed_type;
392 de->
track = parsed_track;
393 de->
count = parsed_count;
408 }
else if (
id == 0 && gid > 0) {
415 "an event var set. The signature event var is "
416 "given precedence over the threshold.conf one. "
417 "We'll change this in the future though.",
426 de->
type = parsed_type;
427 de->
track = parsed_track;
428 de->
count = parsed_count;
443 }
else if (
id > 0 && gid == 0) {
444 SCLogError(
"Can't use a event config that has "
445 "sid > 0 and gid == 0. Please fix this "
446 "in your threshold.conf file");
451 "%" PRIu32
", gid %" PRIu32
": unknown rule",
461 "a threshold set. The signature event var is "
462 "given precedence over the threshold.conf one. "
472 "a detection_filter set. The signature event var is "
473 "given precedence over the threshold.conf one. "
493 de->
type = parsed_type;
494 de->
track = parsed_track;
495 de->
count = parsed_count;
521 uint32_t *ret_gid, uint8_t *ret_parsed_type, uint8_t *ret_parsed_track,
522 uint32_t *ret_parsed_count, uint32_t *ret_parsed_seconds, uint32_t *ret_parsed_timeout,
523 uint8_t *ret_parsed_new_action,
char **ret_th_ip)
525 char th_rule_type[32];
528 const char *rule_extend = NULL;
529 char th_type[16] =
"";
530 char th_track[16] =
"";
531 char th_count[16] =
"";
532 char th_seconds[16] =
"";
533 char th_new_action[16] =
"";
534 char th_timeout[16] =
"";
535 const char *th_ip = NULL;
537 uint8_t parsed_type = 0;
538 uint8_t parsed_track = 0;
539 uint8_t parsed_new_action = 0;
540 uint32_t parsed_count = 0;
541 uint32_t parsed_seconds = 0;
542 uint32_t parsed_timeout = 0;
545 uint32_t
id = 0, gid = 0;
551 pcre2_match_data *regex_base_match = NULL;
554 SCLogError(
"pcre2_match parse error, ret %" PRId32
", string %s", ret, rawstr);
555 pcre2_match_data_free(regex_base_match);
560 size_t copylen =
sizeof(th_rule_type);
561 ret = pcre2_substring_copy_bynumber(
562 regex_base_match, 1, (PCRE2_UCHAR8 *)th_rule_type, ©len);
564 SCLogError(
"pcre2_substring_copy_bynumber failed");
565 pcre2_match_data_free(regex_base_match);
570 copylen =
sizeof(th_gid);
571 ret = pcre2_substring_copy_bynumber(regex_base_match, 2, (PCRE2_UCHAR8 *)th_gid, ©len);
573 SCLogError(
"pcre2_substring_copy_bynumber failed");
574 pcre2_match_data_free(regex_base_match);
578 copylen =
sizeof(th_sid);
579 ret = pcre2_substring_copy_bynumber(regex_base_match, 3, (PCRE2_UCHAR8 *)th_sid, ©len);
581 SCLogError(
"pcre2_substring_copy_bynumber failed");
582 pcre2_match_data_free(regex_base_match);
587 ret = pcre2_substring_get_bynumber(
588 regex_base_match, 4, (PCRE2_UCHAR8 **)&rule_extend, ©len);
590 SCLogError(
"pcre2_substring_get_bynumber failed");
591 pcre2_match_data_free(regex_base_match);
594 pcre2_match_data_free(regex_base_match);
595 regex_base_match = NULL;
598 if (strcasecmp(th_rule_type,
"event_filter") == 0) {
600 }
else if (strcasecmp(th_rule_type,
"threshold") == 0) {
602 }
else if (strcasecmp(th_rule_type,
"rate_filter") == 0) {
604 }
else if (strcasecmp(th_rule_type,
"suppress") == 0) {
607 SCLogError(
"rule type %s is unknown", th_rule_type);
615 if (strlen(rule_extend) > 0) {
616 pcre2_match_data *match = NULL;
620 SCLogError(
"pcre2_match parse error, ret %" PRId32
", string %s", ret,
622 pcre2_match_data_free(match);
626 copylen =
sizeof(th_type);
627 ret = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)th_type, ©len);
629 SCLogError(
"pcre2_substring_copy_bynumber failed");
630 pcre2_match_data_free(match);
634 copylen =
sizeof(th_track);
635 ret = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)th_track, ©len);
637 SCLogError(
"pcre2_substring_copy_bynumber failed");
638 pcre2_match_data_free(match);
642 copylen =
sizeof(th_count);
643 ret = pcre2_substring_copy_bynumber(match, 3, (PCRE2_UCHAR8 *)th_count, ©len);
645 SCLogError(
"pcre2_substring_copy_bynumber failed");
646 pcre2_match_data_free(match);
650 copylen =
sizeof(th_seconds);
651 ret = pcre2_substring_copy_bynumber(match, 4, (PCRE2_UCHAR8 *)th_seconds, ©len);
653 SCLogError(
"pcre2_substring_copy_bynumber failed");
654 pcre2_match_data_free(match);
657 pcre2_match_data_free(match);
659 if (strcasecmp(th_type,
"limit") == 0)
661 else if (strcasecmp(th_type,
"both") == 0)
663 else if (strcasecmp(th_type,
"threshold") == 0)
666 SCLogError(
"limit type not supported: %s", th_type);
675 if (strlen(rule_extend) > 0) {
676 pcre2_match_data *match = NULL;
679 SCLogError(
"pcre2_match parse error, ret %" PRId32
", string %s", ret,
681 pcre2_match_data_free(match);
685 copylen =
sizeof(th_seconds);
686 ret = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)th_track, ©len);
688 SCLogError(
"pcre2_substring_copy_bynumber failed");
689 pcre2_match_data_free(match);
693 ret = pcre2_substring_get_bynumber(match, 2, (PCRE2_UCHAR8 **)&th_ip, ©len);
695 SCLogError(
"pcre2_substring_get_bynumber failed");
696 pcre2_match_data_free(match);
699 pcre2_match_data_free(match);
706 if (strlen(rule_extend) > 0) {
707 pcre2_match_data *match = NULL;
710 SCLogError(
"pcre2_match parse error, ret %" PRId32
", string %s", ret,
712 pcre2_match_data_free(match);
716 copylen =
sizeof(th_track);
717 ret = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)th_track, ©len);
719 SCLogError(
"pcre2_substring_copy_bynumber failed");
720 pcre2_match_data_free(match);
724 copylen =
sizeof(th_count);
725 ret = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)th_count, ©len);
727 SCLogError(
"pcre2_substring_copy_bynumber failed");
728 pcre2_match_data_free(match);
732 copylen =
sizeof(th_seconds);
733 ret = pcre2_substring_copy_bynumber(match, 3, (PCRE2_UCHAR8 *)th_seconds, ©len);
735 SCLogError(
"pcre2_substring_copy_bynumber failed");
736 pcre2_match_data_free(match);
740 copylen =
sizeof(th_new_action);
741 ret = pcre2_substring_copy_bynumber(
742 match, 4, (PCRE2_UCHAR8 *)th_new_action, ©len);
744 SCLogError(
"pcre2_substring_copy_bynumber failed");
745 pcre2_match_data_free(match);
749 copylen =
sizeof(th_timeout);
750 ret = pcre2_substring_copy_bynumber(match, 5, (PCRE2_UCHAR8 *)th_timeout, ©len);
752 SCLogError(
"pcre2_substring_copy_bynumber failed");
753 pcre2_match_data_free(match);
756 pcre2_match_data_free(match);
760 if (
StringParseUint32(&parsed_timeout, 10,
sizeof(th_timeout), th_timeout) <= 0) {
765 if (strcasecmp(th_new_action,
"alert") == 0)
767 if (strcasecmp(th_new_action,
"drop") == 0)
769 if (strcasecmp(th_new_action,
"pass") == 0)
771 if (strcasecmp(th_new_action,
"reject") == 0)
773 if (strcasecmp(th_new_action,
"log") == 0) {
774 SCLogInfo(
"log action for rate_filter not supported yet");
777 if (strcasecmp(th_new_action,
"sdrop") == 0) {
778 SCLogInfo(
"sdrop action for rate_filter not supported yet");
794 if (strcasecmp(th_track,
"by_dst") == 0)
796 else if (strcasecmp(th_track,
"by_src") == 0)
798 else if (strcasecmp(th_track,
"by_both") == 0) {
801 else if (strcasecmp(th_track,
"by_rule") == 0)
803 else if (strcasecmp(th_track,
"by_flow") == 0)
806 SCLogError(
"Invalid track parameter %s in %s", th_track, rawstr);
813 if (parsed_count == 0) {
814 SCLogError(
"rate filter count should be > 0");
818 if (
StringParseUint32(&parsed_seconds, 10,
sizeof(th_seconds), th_seconds) <= 0) {
825 if (strcmp(
"", th_track) != 0) {
826 if (strcasecmp(th_track,
"by_dst") == 0)
828 else if (strcasecmp(th_track,
"by_src") == 0)
830 else if (strcasecmp(th_track,
"by_either") == 0) {
834 SCLogError(
"Invalid track parameter %s in %s", th_track, rule_extend);
851 *ret_parsed_type = parsed_type;
852 *ret_parsed_track = parsed_track;
853 *ret_parsed_new_action = parsed_new_action;
854 *ret_parsed_count = parsed_count;
855 *ret_parsed_seconds = parsed_seconds;
856 *ret_parsed_timeout = parsed_timeout;
859 *ret_th_ip = (
char *)th_ip;
861 pcre2_substring_free((PCRE2_UCHAR8 *)rule_extend);
865 if (rule_extend != NULL) {
866 pcre2_substring_free((PCRE2_UCHAR8 *)rule_extend);
869 pcre2_substring_free((PCRE2_UCHAR8 *)th_ip);
886 uint8_t parsed_type = 0;
887 uint8_t parsed_track = 0;
888 uint8_t parsed_new_action = 0;
889 uint32_t parsed_count = 0;
890 uint32_t parsed_seconds = 0;
891 uint32_t parsed_timeout = 0;
893 uint32_t
id = 0, gid = 0;
895 int r = ParseThresholdRule(
de_ctx, rawstr, &
id, &gid, &parsed_type, &parsed_track,
896 &parsed_count, &parsed_seconds, &parsed_timeout, &parsed_new_action, &th_ip);
901 r = SetupSuppressRule(
de_ctx,
id, gid, parsed_type, parsed_track,
902 parsed_count, parsed_seconds, parsed_timeout, parsed_new_action,
905 r = SetupThresholdRule(
de_ctx,
id, gid, parsed_type, parsed_track, parsed_count,
906 parsed_seconds, parsed_timeout, parsed_new_action);
912 pcre2_substring_free((PCRE2_UCHAR8 *)th_ip);
916 pcre2_substring_free((PCRE2_UCHAR8 *)th_ip);
932 static int SCThresholdConfIsLineBlankOrComment(
char *line)
934 while (*line !=
'\0') {
940 if (!isspace((
unsigned char)*line))
958 static int SCThresholdConfLineIsMultiline(
char *line)
962 size_t len = strlen(line);
964 while (line < rline +
len && *line !=
'\n') {
967 flag = (int)(line - rline);
969 if (!isspace((
unsigned char)*line))
987 char line[8192] =
"";
996 while (fgets(line + esc_pos, (
int)
sizeof(line) - esc_pos, fp) != NULL) {
997 if (SCThresholdConfIsLineBlankOrComment(line)) {
1001 esc_pos = SCThresholdConfLineIsMultiline(line);
1003 if (SCThresholdConfAddThresholdtype(line,
de_ctx) < 0) {
1007 SCLogDebug(
"Adding threshold.config rule num %" PRIu32
"( %s )", rule_num, line);
1017 SCLogInfo(
"Threshold config parsed: %d rule(s) found", rule_num);
1031 static FILE *SCThresholdConfGenerateValidDummyFD01(
void)
1034 const char *buffer =
1035 "event_filter gen_id 1, sig_id 10, type limit, track by_src, count 1, seconds 60\n"
1036 "threshold gen_id 1, sig_id 100, type both, track by_dst, count 10, seconds 60\n"
1037 "event_filter gen_id 1, sig_id 1000, type threshold, track by_src, count 100, seconds 60\n";
1039 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1041 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1052 static FILE *SCThresholdConfGenerateInvalidDummyFD02(
void)
1055 const char *buffer =
1056 "event_filter gen_id 1, sig_id 1000, type invalid, track by_src, count 100, seconds 60\n";
1058 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1060 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1070 static FILE *SCThresholdConfGenerateValidDummyFD03(
void)
1073 const char *buffer =
1074 "event_filter gen_id 0, sig_id 0, type threshold, track by_src, count 100, seconds 60\n";
1076 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1078 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1089 static FILE *SCThresholdConfGenerateValidDummyFD04(
void)
1092 const char *buffer =
1093 "event_filter gen_id 1 \\\n, sig_id 10, type limit, track by_src, \\\ncount 1, seconds 60\n"
1094 "threshold gen_id 1, \\\nsig_id 100, type both\\\n, track by_dst, count 10, \\\n seconds 60\n"
1095 "event_filter gen_id 1, sig_id 1000, \\\ntype threshold, track \\\nby_src, count 100, seconds 60\n";
1097 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1099 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1109 static FILE *SCThresholdConfGenerateValidDummyFD05(
void)
1112 const char *buffer =
1113 "rate_filter gen_id 1, sig_id 10, track by_src, count 1, seconds 60, new_action drop, timeout 10\n"
1114 "rate_filter gen_id 1, sig_id 100, track by_dst, count 10, seconds 60, new_action pass, timeout 5\n"
1115 "rate_filter gen_id 1, sig_id 1000, track by_rule, count 100, seconds 60, new_action alert, timeout 30\n"
1116 "rate_filter gen_id 1, sig_id 10000, track by_both, count 1000, seconds 60, new_action reject, timeout 21\n";
1118 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1120 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1131 static FILE *SCThresholdConfGenerateValidDummyFD06(
void)
1134 const char *buffer =
1135 "rate_filter \\\ngen_id 1, sig_id 10, track by_src, count 1, seconds 60\\\n, new_action drop, timeout 10\n"
1136 "rate_filter gen_id 1, \\\nsig_id 100, track by_dst, \\\ncount 10, seconds 60, new_action pass, timeout 5\n"
1137 "rate_filter gen_id 1, sig_id 1000, \\\ntrack by_rule, count 100, seconds 60, new_action alert, timeout 30\n"
1138 "rate_filter gen_id 1, sig_id 10000, track by_both, count 1000, \\\nseconds 60, new_action reject, timeout 21\n";
1140 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1142 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1153 static FILE *SCThresholdConfGenerateValidDummyFD07(
void)
1156 const char *buffer =
1157 "rate_filter gen_id 1, sig_id 10, track by_src, count 3, seconds 3, new_action drop, timeout 10\n"
1158 "rate_filter gen_id 1, sig_id 11, track by_src, count 3, seconds 1, new_action drop, timeout 5\n";
1160 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1162 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1172 static FILE *SCThresholdConfGenerateValidDummyFD08(
void)
1175 const char *buffer =
1176 "rate_filter gen_id 1, sig_id 10, track by_rule, count 3, seconds 3, new_action drop, timeout 10\n";
1178 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1180 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1191 static FILE *SCThresholdConfGenerateValidDummyFD09(
void)
1194 const char *buffer =
1195 "event_filter gen_id 1 \\\n, sig_id 10, type limit, track by_src, \\\ncount 2, seconds 60\n"
1196 "threshold gen_id 1, \\\nsig_id 11, type threshold\\\n, track by_dst, count 3, \\\n seconds 60\n"
1197 "event_filter gen_id 1, sig_id 12, \\\ntype both, track \\\nby_src, count 2, seconds 60\n";
1199 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1201 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1212 static FILE *SCThresholdConfGenerateValidDummyFD10(
void)
1215 const char *buffer =
1216 "event_filter gen_id 1 \\\n, sig_id 10, type limit, track by_src, \\\ncount 5, seconds 2\n"
1217 "threshold gen_id 1, \\\nsig_id 11, type threshold\\\n, track by_dst, count 5, \\\n seconds 2\n"
1218 "event_filter gen_id 1, sig_id 12, \\\ntype both, track \\\nby_src, count 5, seconds 2\n";
1220 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1222 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1232 static FILE *SCThresholdConfGenerateValidDummyFD11(
void)
1235 const char *buffer =
1236 "suppress gen_id 1, sig_id 10000\n"
1237 "suppress gen_id 1, sig_id 1000, track by_src, ip 192.168.1.1\n";
1239 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1241 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1252 static int SCThresholdConfTest01(
void)
1259 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:10;)");
1263 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD01();
1285 static int SCThresholdConfTest02(
void)
1292 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:100;)");
1296 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD01();
1318 static int SCThresholdConfTest03(
void)
1325 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:1000;)");
1329 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD01();
1351 static int SCThresholdConfTest04(
void)
1358 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:1000;)");
1362 g_ut_threshold_fp = SCThresholdConfGenerateInvalidDummyFD02();
1380 static int SCThresholdConfTest05(
void)
1387 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:1;)");
1390 "alert tcp any any -> any 80 (msg:\"Threshold limit\"; gid:1; sid:10;)");
1394 "alert tcp any any -> any 80 (msg:\"Threshold limit\"; gid:1; sid:100;)");
1398 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD03();
1436 static int SCThresholdConfTest06(
void)
1443 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:10;)");
1447 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD04();
1469 static int SCThresholdConfTest07(
void)
1476 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:10;)");
1480 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD05();
1503 static int SCThresholdConfTest08(
void)
1510 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:10;)");
1514 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD06();
1536 static int SCThresholdConfTest09(
void)
1539 memset(&th_v, 0,
sizeof(th_v));
1554 "alert tcp any any -> any any (msg:\"ratefilter test\"; gid:1; sid:10;)");
1558 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD07();
1622 static int SCThresholdConfTest10(
void)
1630 "172.26.0.2",
"172.26.0.11");
1633 "172.26.0.1",
"172.26.0.10");
1637 memset(&th_v, 0,
sizeof(th_v));
1646 "alert tcp any any -> any any (msg:\"ratefilter test\"; gid:1; sid:10;)");
1650 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD08();
1714 static int SCThresholdConfTest11(
void)
1722 memset(&th_v, 0,
sizeof(th_v));
1731 "alert tcp any any -> any any (msg:\"event_filter test limit\"; gid:1; sid:10;)");
1734 "alert tcp any any -> any any (msg:\"event_filter test threshold\"; gid:1; sid:11;)");
1737 "alert tcp any any -> any any (msg:\"event_filter test both\"; gid:1; sid:12;)");
1741 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD09();
1821 static int SCThresholdConfTest12(
void)
1829 memset(&th_v, 0,
sizeof(th_v));
1838 "alert tcp any any -> any any (msg:\"event_filter test limit\"; gid:1; sid:10;)");
1841 "alert tcp any any -> any any (msg:\"event_filter test threshold\"; gid:1; sid:11;)");
1844 "alert tcp any any -> any any (msg:\"event_filter test both\"; gid:1; sid:12;)");
1848 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD10();
1928 static int SCThresholdConfTest13(
void)
1935 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:1000;)");
1939 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD11();
1961 static int SCThresholdConfTest14(
void)
1966 "192.168.0.100", 1234, 24);
1969 "192.168.0.100", 1234, 24);
1978 "alert tcp any any -> any any (msg:\"suppress test\"; gid:1; sid:10000;)");
1981 "alert tcp any any -> any any (msg:\"suppress test 2\"; gid:1; sid:10;)");
1984 "alert tcp any any -> any any (msg:\"suppress test 3\"; gid:1; sid:1000;)");
1988 memset(&th_v, 0,
sizeof(th_v));
1992 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD11();
2024 static int SCThresholdConfTest15(
void)
2029 "192.168.0.100", 1234, 24);
2033 memset(&th_v, 0,
sizeof(th_v));
2042 "drop tcp any any -> any any (msg:\"suppress test\"; content:\"lalala\"; gid:1; sid:10000;)");
2046 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD11();
2074 static int SCThresholdConfTest16(
void)
2079 "192.168.0.100", 1234, 24);
2083 memset(&th_v, 0,
sizeof(th_v));
2092 "drop tcp any any -> any any (msg:\"suppress test\"; gid:1; sid:1000;)");
2096 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD11();
2123 static int SCThresholdConfTest17(
void)
2128 "192.168.0.100", 1234, 24);
2132 memset(&th_v, 0,
sizeof(th_v));
2141 "drop tcp 192.168.0.10 any -> 192.168.0.100 any (msg:\"suppress test\"; gid:1; sid:10000;)");
2145 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD11();
2172 static FILE *SCThresholdConfGenerateInvalidDummyFD12(
void)
2175 const char *buffer =
2176 "suppress gen_id 1, sig_id 2200029, track by_dst, ip fe80::/16\n"
2177 "suppress gen_id 1, sig_id 2200029, track by_stc, ip fe80::/16\n";
2179 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
2181 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
2192 static int SCThresholdConfTest18(
void)
2200 "alert tcp 192.168.0.10 any -> 192.168.0.100 any (msg:\"suppress test\"; gid:1; sid:2200029;)");
2203 g_ut_threshold_fp = SCThresholdConfGenerateInvalidDummyFD12();
2224 static FILE *SCThresholdConfGenerateInvalidDummyFD13(
void)
2227 const char *buffer =
2228 "suppress gen_id 1, sig_id 2200029, track by_stc, ip fe80::/16\n"
2229 "suppress gen_id 1, sig_id 2200029, track by_dst, ip fe80::/16\n";
2231 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
2233 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
2244 static int SCThresholdConfTest19(
void)
2251 "alert tcp 192.168.0.10 any -> 192.168.0.100 any (msg:\"suppress test\"; gid:1; sid:2200029;)");
2254 g_ut_threshold_fp = SCThresholdConfGenerateInvalidDummyFD13();
2273 static FILE *SCThresholdConfGenerateValidDummyFD20(
void)
2276 const char *buffer =
2277 "suppress gen_id 1, sig_id 1000, track by_src, ip 2.2.3.4\n"
2278 "suppress gen_id 1, sig_id 1000, track by_src, ip 1.2.3.4\n"
2279 "suppress gen_id 1, sig_id 1000, track by_src, ip 192.168.1.1\n";
2281 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
2283 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
2294 static int SCThresholdConfTest20(
void)
2301 "alert tcp any any -> any any (msg:\"Threshold limit\"; content:\"abc\"; sid:1000;)");
2304 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD20();
2340 static int SCThresholdConfTest21(
void)
2347 "alert tcp any any -> any any (msg:\"Threshold limit\"; content:\"abc\"; threshold: type limit, track by_dst, count 5, seconds 60; sid:1000;)");
2349 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD20();
2383 static FILE *SCThresholdConfGenerateValidDummyFD22(
void)
2386 const char *buffer =
2387 "rate_filter gen_id 1, sig_id 10, track by_both, count 2, seconds 5, new_action drop, timeout 6\n";
2389 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
2391 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
2402 static int SCThresholdConfTest22(
void)
2405 memset(&th_v, 0,
sizeof(th_v));
2429 "alert tcp any any -> any any (msg:\"ratefilter by_both test\"; gid:1; sid:10;)");
2433 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD22();
2441 p2->
ts = p3->
ts = p1->
ts;
2460 p2->
ts = p3->
ts = p1->
ts;
2471 p2->
ts = p3->
ts = p1->
ts;
2490 p2->
ts = p3->
ts = p1->
ts;
2521 static FILE *SCThresholdConfGenerateValidDummyFD23(
void)
2524 const char *buffer =
2525 "rate_filter gen_id 1, sig_id 10, track by_both, count 1, seconds 5, new_action drop, timeout 6\n";
2527 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
2529 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
2541 static int SCThresholdConfTest23(
void)
2544 memset(&th_v, 0,
sizeof(th_v));
2563 "alert tcp any any -> any any (msg:\"ratefilter by_both test\"; gid:1; sid:10;)");
2567 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD23();
2615 SCThresholdConfTest09);
2617 SCThresholdConfTest10);
2619 SCThresholdConfTest11);
2621 SCThresholdConfTest12);
2623 UtRegisterTest(
"SCThresholdConfTest14 - suppress", SCThresholdConfTest14);
2625 SCThresholdConfTest15);
2627 SCThresholdConfTest16);
2629 SCThresholdConfTest17);
2632 SCThresholdConfTest18);
2634 SCThresholdConfTest19);
2636 SCThresholdConfTest20);
2638 SCThresholdConfTest21);
2640 SCThresholdConfTest22);
2641 UtRegisterTest(
"SCThresholdConfTest23 - rate_filter by_both opposite",
2642 SCThresholdConfTest23);