40 #define PARSE_REGEX "([0x]*[0-9a-f]+)/([0x]*[0-9a-f]+)"
48 #if defined UNITTESTS && defined NFQ
49 static void MarkRegisterTests(
void);
62 #if defined UNITTESTS && defined NFQ
78 static void * DetectMarkParse (
const char *rawstr)
82 const char *str_ptr = NULL;
89 pcre2_match_data *match = NULL;
92 SCLogError(
"pcre_exec parse error, ret %" PRId32
", string %s", ret, rawstr);
93 pcre2_match_data_free(match);
97 res = pcre2_substring_get_bynumber(match, 1, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
99 SCLogError(
"pcre2_substring_get_bynumber failed");
103 ptr = (
char *)str_ptr;
109 mark = strtoul(ptr, &endptr, 0);
110 if (errno == ERANGE) {
112 pcre2_substring_free((PCRE2_UCHAR8 *)ptr);
116 else if (endptr == ptr && mark == 0) {
118 pcre2_substring_free((PCRE2_UCHAR8 *)ptr);
120 }
else if (endptr == ptr) {
122 pcre2_substring_free((PCRE2_UCHAR8 *)ptr);
126 res = pcre2_substring_get_bynumber(match, 2, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
128 SCLogError(
"pcre2_substring_get_bynumber failed");
132 pcre2_substring_free((PCRE2_UCHAR8 *)ptr);
133 ptr = (
char *)str_ptr;
142 pcre2_match_data_free(match);
147 mask = strtoul(ptr, &endptr, 0);
148 if (errno == ERANGE) {
150 pcre2_substring_free((PCRE2_UCHAR8 *)ptr);
154 else if (endptr == ptr && mask == 0) {
156 pcre2_substring_free((PCRE2_UCHAR8 *)ptr);
159 else if (endptr == ptr) {
161 pcre2_substring_free((PCRE2_UCHAR8 *)ptr);
165 SCLogDebug(
"Rule will set mark 0x%x with mask 0x%x", mark, mask);
166 pcre2_substring_free((PCRE2_UCHAR8 *)ptr);
174 pcre2_match_data_free(match);
179 pcre2_match_data_free(match);
231 if (PacketIsNotTunnel(p)) {
263 #if defined UNITTESTS && defined NFQ
268 static int MarkTestParse01 (
void)
272 data = DetectMarkParse(
"1/1");
284 static int MarkTestParse02 (
void)
288 data = DetectMarkParse(
"4");
300 static int MarkTestParse03 (
void)
304 data = DetectMarkParse(
"0x10/0xff");
316 static int MarkTestParse04 (
void)
320 data = DetectMarkParse(
"0x1g/0xff");
331 static void MarkRegisterTests(
void)