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);
191 SCLogWarning(
"Error loading threshold configuration from %s", filename);
192 SCThresholdConfDeInitContext(
de_ctx, fd);
199 SCThresholdConfDeInitContext(
de_ctx, fd);
202 g_ut_threshold_fp = NULL;
204 SCLogDebug(
"Global thresholding options defined");
226 uint8_t parsed_type, uint8_t parsed_track, uint32_t parsed_count,
227 uint32_t parsed_seconds, uint32_t parsed_timeout, uint8_t parsed_new_action,
242 orig_de->
track = parsed_track;
243 orig_de->
count = parsed_count;
244 orig_de->
seconds = parsed_seconds;
246 orig_de->
timeout = parsed_timeout;
255 if (
id == 0 && gid == 0) {
277 }
else if (
id == 0 && gid > 0) {
279 SCLogWarning(
"suppressing all rules with gid %" PRIu32, gid);
301 }
else if (
id > 0 && gid == 0) {
302 SCLogError(
"Can't use a event config that has "
303 "sid > 0 and gid == 0. Please fix this "
304 "in your threshold.config file");
310 "%" PRIu32
", gid %" PRIu32
": unknown rule",
330 if (orig_de != NULL) {
336 if (orig_de != NULL) {
353 uint8_t parsed_type, uint8_t parsed_track, uint32_t parsed_count, uint32_t parsed_seconds,
354 uint32_t parsed_timeout, uint8_t parsed_new_action)
363 if (
id == 0 && gid == 0) {
368 "an event var set. The signature event var is "
369 "given precedence over the threshold.conf one. "
370 "We'll change this in the future though.",
379 "an event var set. The signature event var is "
380 "given precedence over the threshold.conf one. "
381 "We'll change this in the future though.",
390 de->
type = parsed_type;
391 de->
track = parsed_track;
392 de->
count = parsed_count;
407 }
else if (
id == 0 && gid > 0) {
414 "an event var set. The signature event var is "
415 "given precedence over the threshold.conf one. "
416 "We'll change this in the future though.",
425 de->
type = parsed_type;
426 de->
track = parsed_track;
427 de->
count = parsed_count;
442 }
else if (
id > 0 && gid == 0) {
443 SCLogError(
"Can't use a event config that has "
444 "sid > 0 and gid == 0. Please fix this "
445 "in your threshold.conf file");
450 "%" PRIu32
", gid %" PRIu32
": unknown rule",
460 "a threshold set. The signature event var is "
461 "given precedence over the threshold.conf one. "
471 "a detection_filter set. The signature event var is "
472 "given precedence over the threshold.conf one. "
492 de->
type = parsed_type;
493 de->
track = parsed_track;
494 de->
count = parsed_count;
520 uint32_t *ret_gid, uint8_t *ret_parsed_type, uint8_t *ret_parsed_track,
521 uint32_t *ret_parsed_count, uint32_t *ret_parsed_seconds, uint32_t *ret_parsed_timeout,
522 uint8_t *ret_parsed_new_action,
char **ret_th_ip)
524 char th_rule_type[32];
527 const char *rule_extend = NULL;
528 char th_type[16] =
"";
529 char th_track[16] =
"";
530 char th_count[16] =
"";
531 char th_seconds[16] =
"";
532 char th_new_action[16] =
"";
533 char th_timeout[16] =
"";
534 const char *th_ip = NULL;
536 uint8_t parsed_type = 0;
537 uint8_t parsed_track = 0;
538 uint8_t parsed_new_action = 0;
539 uint32_t parsed_count = 0;
540 uint32_t parsed_seconds = 0;
541 uint32_t parsed_timeout = 0;
544 uint32_t
id = 0, gid = 0;
550 pcre2_match_data *regex_base_match = NULL;
553 SCLogError(
"pcre2_match parse error, ret %" PRId32
", string %s", ret, rawstr);
554 pcre2_match_data_free(regex_base_match);
559 size_t copylen =
sizeof(th_rule_type);
560 ret = pcre2_substring_copy_bynumber(
561 regex_base_match, 1, (PCRE2_UCHAR8 *)th_rule_type, ©len);
563 SCLogError(
"pcre2_substring_copy_bynumber failed");
564 pcre2_match_data_free(regex_base_match);
569 copylen =
sizeof(th_gid);
570 ret = pcre2_substring_copy_bynumber(regex_base_match, 2, (PCRE2_UCHAR8 *)th_gid, ©len);
572 SCLogError(
"pcre2_substring_copy_bynumber failed");
573 pcre2_match_data_free(regex_base_match);
577 copylen =
sizeof(th_sid);
578 ret = pcre2_substring_copy_bynumber(regex_base_match, 3, (PCRE2_UCHAR8 *)th_sid, ©len);
580 SCLogError(
"pcre2_substring_copy_bynumber failed");
581 pcre2_match_data_free(regex_base_match);
586 ret = pcre2_substring_get_bynumber(
587 regex_base_match, 4, (PCRE2_UCHAR8 **)&rule_extend, ©len);
589 SCLogError(
"pcre2_substring_get_bynumber failed");
590 pcre2_match_data_free(regex_base_match);
593 pcre2_match_data_free(regex_base_match);
594 regex_base_match = NULL;
597 if (strcasecmp(th_rule_type,
"event_filter") == 0) {
599 }
else if (strcasecmp(th_rule_type,
"threshold") == 0) {
601 }
else if (strcasecmp(th_rule_type,
"rate_filter") == 0) {
603 }
else if (strcasecmp(th_rule_type,
"suppress") == 0) {
606 SCLogError(
"rule type %s is unknown", th_rule_type);
614 if (strlen(rule_extend) > 0) {
615 pcre2_match_data *match = NULL;
619 SCLogError(
"pcre2_match parse error, ret %" PRId32
", string %s", ret,
621 pcre2_match_data_free(match);
625 copylen =
sizeof(th_type);
626 ret = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)th_type, ©len);
628 SCLogError(
"pcre2_substring_copy_bynumber failed");
629 pcre2_match_data_free(match);
633 copylen =
sizeof(th_track);
634 ret = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)th_track, ©len);
636 SCLogError(
"pcre2_substring_copy_bynumber failed");
637 pcre2_match_data_free(match);
641 copylen =
sizeof(th_count);
642 ret = pcre2_substring_copy_bynumber(match, 3, (PCRE2_UCHAR8 *)th_count, ©len);
644 SCLogError(
"pcre2_substring_copy_bynumber failed");
645 pcre2_match_data_free(match);
649 copylen =
sizeof(th_seconds);
650 ret = pcre2_substring_copy_bynumber(match, 4, (PCRE2_UCHAR8 *)th_seconds, ©len);
652 SCLogError(
"pcre2_substring_copy_bynumber failed");
653 pcre2_match_data_free(match);
656 pcre2_match_data_free(match);
658 if (strcasecmp(th_type,
"limit") == 0)
660 else if (strcasecmp(th_type,
"both") == 0)
662 else if (strcasecmp(th_type,
"threshold") == 0)
665 SCLogError(
"limit type not supported: %s", th_type);
674 if (strlen(rule_extend) > 0) {
675 pcre2_match_data *match = NULL;
678 SCLogError(
"pcre2_match parse error, ret %" PRId32
", string %s", ret,
680 pcre2_match_data_free(match);
684 copylen =
sizeof(th_seconds);
685 ret = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)th_track, ©len);
687 SCLogError(
"pcre2_substring_copy_bynumber failed");
688 pcre2_match_data_free(match);
692 ret = pcre2_substring_get_bynumber(match, 2, (PCRE2_UCHAR8 **)&th_ip, ©len);
694 SCLogError(
"pcre2_substring_get_bynumber failed");
695 pcre2_match_data_free(match);
698 pcre2_match_data_free(match);
705 if (strlen(rule_extend) > 0) {
706 pcre2_match_data *match = NULL;
709 SCLogError(
"pcre2_match parse error, ret %" PRId32
", string %s", ret,
711 pcre2_match_data_free(match);
715 copylen =
sizeof(th_track);
716 ret = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)th_track, ©len);
718 SCLogError(
"pcre2_substring_copy_bynumber failed");
719 pcre2_match_data_free(match);
723 copylen =
sizeof(th_count);
724 ret = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)th_count, ©len);
726 SCLogError(
"pcre2_substring_copy_bynumber failed");
727 pcre2_match_data_free(match);
731 copylen =
sizeof(th_seconds);
732 ret = pcre2_substring_copy_bynumber(match, 3, (PCRE2_UCHAR8 *)th_seconds, ©len);
734 SCLogError(
"pcre2_substring_copy_bynumber failed");
735 pcre2_match_data_free(match);
739 copylen =
sizeof(th_new_action);
740 ret = pcre2_substring_copy_bynumber(
741 match, 4, (PCRE2_UCHAR8 *)th_new_action, ©len);
743 SCLogError(
"pcre2_substring_copy_bynumber failed");
744 pcre2_match_data_free(match);
748 copylen =
sizeof(th_timeout);
749 ret = pcre2_substring_copy_bynumber(match, 5, (PCRE2_UCHAR8 *)th_timeout, ©len);
751 SCLogError(
"pcre2_substring_copy_bynumber failed");
752 pcre2_match_data_free(match);
755 pcre2_match_data_free(match);
759 if (
StringParseUint32(&parsed_timeout, 10,
sizeof(th_timeout), th_timeout) <= 0) {
764 if (strcasecmp(th_new_action,
"alert") == 0)
766 if (strcasecmp(th_new_action,
"drop") == 0)
768 if (strcasecmp(th_new_action,
"pass") == 0)
770 if (strcasecmp(th_new_action,
"reject") == 0)
772 if (strcasecmp(th_new_action,
"log") == 0) {
773 SCLogInfo(
"log action for rate_filter not supported yet");
776 if (strcasecmp(th_new_action,
"sdrop") == 0) {
777 SCLogInfo(
"sdrop action for rate_filter not supported yet");
793 if (strcasecmp(th_track,
"by_dst") == 0)
795 else if (strcasecmp(th_track,
"by_src") == 0)
797 else if (strcasecmp(th_track,
"by_both") == 0) {
800 else if (strcasecmp(th_track,
"by_rule") == 0)
802 else if (strcasecmp(th_track,
"by_flow") == 0)
805 SCLogError(
"Invalid track parameter %s in %s", th_track, rawstr);
812 if (parsed_count == 0) {
813 SCLogError(
"rate filter count should be > 0");
817 if (
StringParseUint32(&parsed_seconds, 10,
sizeof(th_seconds), th_seconds) <= 0) {
824 if (strcmp(
"", th_track) != 0) {
825 if (strcasecmp(th_track,
"by_dst") == 0)
827 else if (strcasecmp(th_track,
"by_src") == 0)
829 else if (strcasecmp(th_track,
"by_either") == 0) {
833 SCLogError(
"Invalid track parameter %s in %s", th_track, rule_extend);
850 *ret_parsed_type = parsed_type;
851 *ret_parsed_track = parsed_track;
852 *ret_parsed_new_action = parsed_new_action;
853 *ret_parsed_count = parsed_count;
854 *ret_parsed_seconds = parsed_seconds;
855 *ret_parsed_timeout = parsed_timeout;
858 *ret_th_ip = (
char *)th_ip;
860 pcre2_substring_free((PCRE2_UCHAR8 *)rule_extend);
864 if (rule_extend != NULL) {
865 pcre2_substring_free((PCRE2_UCHAR8 *)rule_extend);
868 pcre2_substring_free((PCRE2_UCHAR8 *)th_ip);
885 uint8_t parsed_type = 0;
886 uint8_t parsed_track = 0;
887 uint8_t parsed_new_action = 0;
888 uint32_t parsed_count = 0;
889 uint32_t parsed_seconds = 0;
890 uint32_t parsed_timeout = 0;
892 uint32_t
id = 0, gid = 0;
894 int r = ParseThresholdRule(
de_ctx, rawstr, &
id, &gid, &parsed_type, &parsed_track,
895 &parsed_count, &parsed_seconds, &parsed_timeout, &parsed_new_action, &th_ip);
900 r = SetupSuppressRule(
de_ctx,
id, gid, parsed_type, parsed_track,
901 parsed_count, parsed_seconds, parsed_timeout, parsed_new_action,
904 r = SetupThresholdRule(
de_ctx,
id, gid, parsed_type, parsed_track, parsed_count,
905 parsed_seconds, parsed_timeout, parsed_new_action);
911 pcre2_substring_free((PCRE2_UCHAR8 *)th_ip);
915 pcre2_substring_free((PCRE2_UCHAR8 *)th_ip);
931 static int SCThresholdConfIsLineBlankOrComment(
char *line)
933 while (*line !=
'\0') {
939 if (!isspace((
unsigned char)*line))
957 static int SCThresholdConfLineIsMultiline(
char *line)
961 size_t len = strlen(line);
963 while (line < rline +
len && *line !=
'\n') {
966 flag = (int)(line - rline);
968 if (!isspace((
unsigned char)*line))
986 char line[8192] =
"";
995 while (fgets(line + esc_pos, (
int)
sizeof(line) - esc_pos, fp) != NULL) {
996 if (SCThresholdConfIsLineBlankOrComment(line)) {
1000 esc_pos = SCThresholdConfLineIsMultiline(line);
1002 if (SCThresholdConfAddThresholdtype(line,
de_ctx) < 0) {
1006 SCLogDebug(
"Adding threshold.config rule num %" PRIu32
"( %s )", rule_num, line);
1016 SCLogInfo(
"Threshold config parsed: %d rule(s) found", rule_num);
1030 static FILE *SCThresholdConfGenerateValidDummyFD01(
void)
1033 const char *buffer =
1034 "event_filter gen_id 1, sig_id 10, type limit, track by_src, count 1, seconds 60\n"
1035 "threshold gen_id 1, sig_id 100, type both, track by_dst, count 10, seconds 60\n"
1036 "event_filter gen_id 1, sig_id 1000, type threshold, track by_src, count 100, seconds 60\n";
1038 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1040 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1051 static FILE *SCThresholdConfGenerateInvalidDummyFD02(
void)
1054 const char *buffer =
1055 "event_filter gen_id 1, sig_id 1000, type invalid, track by_src, count 100, seconds 60\n";
1057 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1059 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1069 static FILE *SCThresholdConfGenerateValidDummyFD03(
void)
1072 const char *buffer =
1073 "event_filter gen_id 0, sig_id 0, type threshold, track by_src, count 100, seconds 60\n";
1075 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1077 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1088 static FILE *SCThresholdConfGenerateValidDummyFD04(
void)
1091 const char *buffer =
1092 "event_filter gen_id 1 \\\n, sig_id 10, type limit, track by_src, \\\ncount 1, seconds 60\n"
1093 "threshold gen_id 1, \\\nsig_id 100, type both\\\n, track by_dst, count 10, \\\n seconds 60\n"
1094 "event_filter gen_id 1, sig_id 1000, \\\ntype threshold, track \\\nby_src, count 100, seconds 60\n";
1096 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1098 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1108 static FILE *SCThresholdConfGenerateValidDummyFD05(
void)
1111 const char *buffer =
1112 "rate_filter gen_id 1, sig_id 10, track by_src, count 1, seconds 60, new_action drop, timeout 10\n"
1113 "rate_filter gen_id 1, sig_id 100, track by_dst, count 10, seconds 60, new_action pass, timeout 5\n"
1114 "rate_filter gen_id 1, sig_id 1000, track by_rule, count 100, seconds 60, new_action alert, timeout 30\n"
1115 "rate_filter gen_id 1, sig_id 10000, track by_both, count 1000, seconds 60, new_action reject, timeout 21\n";
1117 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1119 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1130 static FILE *SCThresholdConfGenerateValidDummyFD06(
void)
1133 const char *buffer =
1134 "rate_filter \\\ngen_id 1, sig_id 10, track by_src, count 1, seconds 60\\\n, new_action drop, timeout 10\n"
1135 "rate_filter gen_id 1, \\\nsig_id 100, track by_dst, \\\ncount 10, seconds 60, new_action pass, timeout 5\n"
1136 "rate_filter gen_id 1, sig_id 1000, \\\ntrack by_rule, count 100, seconds 60, new_action alert, timeout 30\n"
1137 "rate_filter gen_id 1, sig_id 10000, track by_both, count 1000, \\\nseconds 60, new_action reject, timeout 21\n";
1139 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1141 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1152 static FILE *SCThresholdConfGenerateValidDummyFD07(
void)
1155 const char *buffer =
1156 "rate_filter gen_id 1, sig_id 10, track by_src, count 3, seconds 3, new_action drop, timeout 10\n"
1157 "rate_filter gen_id 1, sig_id 11, track by_src, count 3, seconds 1, new_action drop, timeout 5\n";
1159 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1161 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1171 static FILE *SCThresholdConfGenerateValidDummyFD08(
void)
1174 const char *buffer =
1175 "rate_filter gen_id 1, sig_id 10, track by_rule, count 3, seconds 3, new_action drop, timeout 10\n";
1177 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1179 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1190 static FILE *SCThresholdConfGenerateValidDummyFD09(
void)
1193 const char *buffer =
1194 "event_filter gen_id 1 \\\n, sig_id 10, type limit, track by_src, \\\ncount 2, seconds 60\n"
1195 "threshold gen_id 1, \\\nsig_id 11, type threshold\\\n, track by_dst, count 3, \\\n seconds 60\n"
1196 "event_filter gen_id 1, sig_id 12, \\\ntype both, track \\\nby_src, count 2, seconds 60\n";
1198 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1200 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1211 static FILE *SCThresholdConfGenerateValidDummyFD10(
void)
1214 const char *buffer =
1215 "event_filter gen_id 1 \\\n, sig_id 10, type limit, track by_src, \\\ncount 5, seconds 2\n"
1216 "threshold gen_id 1, \\\nsig_id 11, type threshold\\\n, track by_dst, count 5, \\\n seconds 2\n"
1217 "event_filter gen_id 1, sig_id 12, \\\ntype both, track \\\nby_src, count 5, seconds 2\n";
1219 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1221 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1231 static FILE *SCThresholdConfGenerateValidDummyFD11(
void)
1234 const char *buffer =
1235 "suppress gen_id 1, sig_id 10000\n"
1236 "suppress gen_id 1, sig_id 1000, track by_src, ip 192.168.1.1\n";
1238 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
1240 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
1251 static int SCThresholdConfTest01(
void)
1258 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:10;)");
1262 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD01();
1284 static int SCThresholdConfTest02(
void)
1291 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:100;)");
1295 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD01();
1317 static int SCThresholdConfTest03(
void)
1324 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:1000;)");
1328 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD01();
1350 static int SCThresholdConfTest04(
void)
1357 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:1000;)");
1361 g_ut_threshold_fp = SCThresholdConfGenerateInvalidDummyFD02();
1379 static int SCThresholdConfTest05(
void)
1386 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:1;)");
1389 "alert tcp any any -> any 80 (msg:\"Threshold limit\"; gid:1; sid:10;)");
1393 "alert tcp any any -> any 80 (msg:\"Threshold limit\"; gid:1; sid:100;)");
1397 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD03();
1435 static int SCThresholdConfTest06(
void)
1442 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:10;)");
1446 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD04();
1468 static int SCThresholdConfTest07(
void)
1475 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:10;)");
1479 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD05();
1502 static int SCThresholdConfTest08(
void)
1509 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:10;)");
1513 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD06();
1535 static int SCThresholdConfTest09(
void)
1538 memset(&th_v, 0,
sizeof(th_v));
1552 "alert tcp any any -> any any (msg:\"ratefilter test\"; gid:1; sid:10;)");
1556 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD07();
1620 static int SCThresholdConfTest10(
void)
1628 "172.26.0.2",
"172.26.0.11");
1631 "172.26.0.1",
"172.26.0.10");
1635 memset(&th_v, 0,
sizeof(th_v));
1643 "alert tcp any any -> any any (msg:\"ratefilter test\"; gid:1; sid:10;)");
1647 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD08();
1711 static int SCThresholdConfTest11(
void)
1719 memset(&th_v, 0,
sizeof(th_v));
1727 "alert tcp any any -> any any (msg:\"event_filter test limit\"; gid:1; sid:10;)");
1730 "alert tcp any any -> any any (msg:\"event_filter test threshold\"; gid:1; sid:11;)");
1733 "alert tcp any any -> any any (msg:\"event_filter test both\"; gid:1; sid:12;)");
1737 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD09();
1817 static int SCThresholdConfTest12(
void)
1825 memset(&th_v, 0,
sizeof(th_v));
1833 "alert tcp any any -> any any (msg:\"event_filter test limit\"; gid:1; sid:10;)");
1836 "alert tcp any any -> any any (msg:\"event_filter test threshold\"; gid:1; sid:11;)");
1839 "alert tcp any any -> any any (msg:\"event_filter test both\"; gid:1; sid:12;)");
1843 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD10();
1923 static int SCThresholdConfTest13(
void)
1930 "alert tcp any any -> any any (msg:\"Threshold limit\"; gid:1; sid:1000;)");
1934 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD11();
1956 static int SCThresholdConfTest14(
void)
1961 "192.168.0.100", 1234, 24);
1964 "192.168.0.100", 1234, 24);
1973 "alert tcp any any -> any any (msg:\"suppress test\"; gid:1; sid:10000;)");
1976 "alert tcp any any -> any any (msg:\"suppress test 2\"; gid:1; sid:10;)");
1979 "alert tcp any any -> any any (msg:\"suppress test 3\"; gid:1; sid:1000;)");
1983 memset(&th_v, 0,
sizeof(th_v));
1986 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD11();
2018 static int SCThresholdConfTest15(
void)
2023 "192.168.0.100", 1234, 24);
2027 memset(&th_v, 0,
sizeof(th_v));
2035 "drop tcp any any -> any any (msg:\"suppress test\"; content:\"lalala\"; gid:1; sid:10000;)");
2039 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD11();
2067 static int SCThresholdConfTest16(
void)
2072 "192.168.0.100", 1234, 24);
2076 memset(&th_v, 0,
sizeof(th_v));
2084 "drop tcp any any -> any any (msg:\"suppress test\"; gid:1; sid:1000;)");
2088 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD11();
2115 static int SCThresholdConfTest17(
void)
2120 "192.168.0.100", 1234, 24);
2124 memset(&th_v, 0,
sizeof(th_v));
2132 "drop tcp 192.168.0.10 any -> 192.168.0.100 any (msg:\"suppress test\"; gid:1; sid:10000;)");
2136 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD11();
2163 static FILE *SCThresholdConfGenerateInvalidDummyFD12(
void)
2166 const char *buffer =
2167 "suppress gen_id 1, sig_id 2200029, track by_dst, ip fe80::/16\n"
2168 "suppress gen_id 1, sig_id 2200029, track by_stc, ip fe80::/16\n";
2170 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
2172 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
2183 static int SCThresholdConfTest18(
void)
2191 "alert tcp 192.168.0.10 any -> 192.168.0.100 any (msg:\"suppress test\"; gid:1; sid:2200029;)");
2194 g_ut_threshold_fp = SCThresholdConfGenerateInvalidDummyFD12();
2215 static FILE *SCThresholdConfGenerateInvalidDummyFD13(
void)
2218 const char *buffer =
2219 "suppress gen_id 1, sig_id 2200029, track by_stc, ip fe80::/16\n"
2220 "suppress gen_id 1, sig_id 2200029, track by_dst, ip fe80::/16\n";
2222 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
2224 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
2235 static int SCThresholdConfTest19(
void)
2242 "alert tcp 192.168.0.10 any -> 192.168.0.100 any (msg:\"suppress test\"; gid:1; sid:2200029;)");
2245 g_ut_threshold_fp = SCThresholdConfGenerateInvalidDummyFD13();
2264 static FILE *SCThresholdConfGenerateValidDummyFD20(
void)
2267 const char *buffer =
2268 "suppress gen_id 1, sig_id 1000, track by_src, ip 2.2.3.4\n"
2269 "suppress gen_id 1, sig_id 1000, track by_src, ip 1.2.3.4\n"
2270 "suppress gen_id 1, sig_id 1000, track by_src, ip 192.168.1.1\n";
2272 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
2274 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
2285 static int SCThresholdConfTest20(
void)
2292 "alert tcp any any -> any any (msg:\"Threshold limit\"; content:\"abc\"; sid:1000;)");
2295 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD20();
2331 static int SCThresholdConfTest21(
void)
2338 "alert tcp any any -> any any (msg:\"Threshold limit\"; content:\"abc\"; threshold: type limit, track by_dst, count 5, seconds 60; sid:1000;)");
2340 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD20();
2374 static FILE *SCThresholdConfGenerateValidDummyFD22(
void)
2377 const char *buffer =
2378 "rate_filter gen_id 1, sig_id 10, track by_both, count 2, seconds 5, new_action drop, timeout 6\n";
2380 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
2382 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
2393 static int SCThresholdConfTest22(
void)
2396 memset(&th_v, 0,
sizeof(th_v));
2419 "alert tcp any any -> any any (msg:\"ratefilter by_both test\"; gid:1; sid:10;)");
2423 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD22();
2431 p2->
ts = p3->
ts = p1->
ts;
2450 p2->
ts = p3->
ts = p1->
ts;
2461 p2->
ts = p3->
ts = p1->
ts;
2480 p2->
ts = p3->
ts = p1->
ts;
2511 static FILE *SCThresholdConfGenerateValidDummyFD23(
void)
2514 const char *buffer =
2515 "rate_filter gen_id 1, sig_id 10, track by_both, count 1, seconds 5, new_action drop, timeout 6\n";
2517 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
2519 SCLogDebug(
"Error with SCFmemopen() called by Threshold Config test code");
2531 static int SCThresholdConfTest23(
void)
2534 memset(&th_v, 0,
sizeof(th_v));
2552 "alert tcp any any -> any any (msg:\"ratefilter by_both test\"; gid:1; sid:10;)");
2556 g_ut_threshold_fp = SCThresholdConfGenerateValidDummyFD23();
2604 SCThresholdConfTest09);
2606 SCThresholdConfTest10);
2608 SCThresholdConfTest11);
2610 SCThresholdConfTest12);
2612 UtRegisterTest(
"SCThresholdConfTest14 - suppress", SCThresholdConfTest14);
2614 SCThresholdConfTest15);
2616 SCThresholdConfTest16);
2618 SCThresholdConfTest17);
2621 SCThresholdConfTest18);
2623 SCThresholdConfTest19);
2625 SCThresholdConfTest20);
2627 SCThresholdConfTest21);
2629 SCThresholdConfTest22);
2630 UtRegisterTest(
"SCThresholdConfTest23 - rate_filter by_both opposite",
2631 SCThresholdConfTest23);