53 #define PARSE_REGEX "^(?:([\\+\\*!]))?\\s*([MDR]+)"
60 #define MODIFIER_NOT 1
61 #define MODIFIER_PLUS 2
62 #define MODIFIER_ANY 3
64 #define FRAGBITS_HAVE_MF 0x01
65 #define FRAGBITS_HAVE_DF 0x02
66 #define FRAGBITS_HAVE_RF 0x04
76 static bool PrefilterFragBitsIsPrefilterable(
const Signature *s);
78 static void FragBitsRegisterTests(
void);
103 FragBitsMatch(
const uint8_t pbits,
const uint8_t modifier,
108 if ((pbits & dbits) > 0)
113 if (((pbits & dbits) == dbits) && (((pbits - dbits) > 0)))
118 if ((pbits & dbits) != dbits)
148 uint8_t fragbits = 0;
157 return FragBitsMatch(fragbits,
de->modifier,
de->fragbits);
172 int found = 0, res = 0;
174 const char *str_ptr = NULL;
175 char *args[2] = { NULL, NULL};
178 pcre2_match_data *match = NULL;
182 SCLogError(
"pcre_exec parse error, ret %" PRId32
", string %s", ret, rawstr);
186 for (i = 0; i < (ret - 1); i++) {
189 SCLogError(
"pcre2_substring_get_bynumber failed %d", res);
193 args[i] = (
char *)str_ptr;
196 if (args[1] == NULL) {
209 if (args[0] && strlen(args[0])) {
228 while (*ptr !=
'\0') {
255 for (i = 0; i < 2; i++) {
257 pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
259 pcre2_match_data_free(match);
264 pcre2_match_data_free(match);
266 for (i = 0; i < 2; i++) {
268 pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
292 de = DetectFragBitsParse(rawstr);
334 uint8_t fragbits = 0;
342 if (FragBitsMatch(fragbits, ctx->
v1.
u8[0], ctx->
v1.
u8[1]))
371 PrefilterPacketFragBitsSet,
372 PrefilterPacketFragBitsCompare,
373 PrefilterPacketFragBitsMatch);
376 static bool PrefilterFragBitsIsPrefilterable(
const Signature *s)
402 static int FragBitsTestParse01 (
void)
405 de = DetectFragBitsParse(
"M");
407 DetectFragBitsFree(NULL,
de);
420 static int FragBitsTestParse02 (
void)
423 de = DetectFragBitsParse(
"G");
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0x0c ,0x04 ,0x64 ,0x6e,
461 0x73 ,0x31 ,0x04 ,0x6e ,0x6a ,0x69 ,0x74 ,0xc0,
462 0x3c ,0xc0 ,0x34 ,0x00 ,0x02 ,0x00 ,0x01 ,0x00,
463 0x00 ,0x0e ,0x10 ,0x00 ,0x08 ,0x05 ,0x65 ,0x6c,
464 0x7a ,0x69 ,0x70 ,0xc0 ,0x34 ,0xc0 ,0x34 ,0x00,
465 0x02 ,0x00 ,0x01 ,0x00 ,0x00 ,0x0e ,0x10 ,0x00,
466 0x08 ,0x05 ,0x61 ,0x72 ,0x77 ,0x65 ,0x6e ,0xc0,
467 0x34 ,0xc0 ,0x4b ,0x00 ,0x01 ,0x00 ,0x01 ,0x00,
468 0x00 ,0x0e ,0x10 ,0x00 ,0x04 ,0x81 ,0x6f ,0x1a,
469 0x06 ,0xc0 ,0x60 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00,
470 0x00 ,0x0e ,0x10 ,0x00 ,0x04 ,0x81 ,0x6f ,0x1a,
471 0x07 ,0xc0 ,0x73 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00,
472 0x01 ,0x03 ,0x82 ,0x00 ,0x04 ,0x80 ,0xeb ,0xfb,
473 0x0a ,0xc0 ,0x8b ,0x00 ,0x01 ,0x00 ,0x01 ,0x00,
474 0x00 ,0x0e ,0x10 ,0x00 ,0x04 ,0x81 ,0x6f ,0x01,
475 0x0b ,0xc0 ,0x9f ,0x00 ,0x01 ,0x00 ,0x01 ,0x00,
476 0x00 ,0x0e ,0x10 ,0x00 ,0x04 ,0x81 ,0x6f ,0x0b,
489 memset(&ipv4h, 0,
sizeof(
IPV4Hdr));
498 de = DetectFragBitsParse(
"D");
508 ret = DetectFragBitsMatch(NULL, p, NULL, sm->
ctx);
524 static int FragBitsTestParse04 (
void)
526 uint8_t raw_eth[] = {
527 0x00 ,0x40 ,0x33 ,0xd9 ,0x7c ,0xfd ,0x00 ,0x00,
528 0x39 ,0xcf ,0xd9 ,0xcd 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0e ,0x10 ,0x00 ,0x08 ,0x05 ,0x65 ,0x6c,
550 0x7a ,0x69 ,0x70 ,0xc0 ,0x34 ,0xc0 ,0x34 ,0x00,
551 0x02 ,0x00 ,0x01 ,0x00 ,0x00 ,0x0e ,0x10 ,0x00,
552 0x08 ,0x05 ,0x61 ,0x72 ,0x77 ,0x65 ,0x6e ,0xc0,
553 0x34 ,0xc0 ,0x4b ,0x00 ,0x01 ,0x00 ,0x01 ,0x00,
554 0x00 ,0x0e ,0x10 ,0x00 ,0x04 ,0x81 ,0x6f ,0x1a,
555 0x06 ,0xc0 ,0x60 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00,
556 0x00 ,0x0e ,0x10 ,0x00 ,0x04 ,0x81 ,0x6f ,0x1a,
557 0x07 ,0xc0 ,0x73 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00,
558 0x01 ,0x03 ,0x82 ,0x00 ,0x04 ,0x80 ,0xeb ,0xfb,
559 0x0a ,0xc0 ,0x8b ,0x00 ,0x01 ,0x00 ,0x01 ,0x00,
560 0x00 ,0x0e ,0x10 ,0x00 ,0x04 ,0x81 ,0x6f ,0x01,
561 0x0b ,0xc0 ,0x9f ,0x00 ,0x01 ,0x00 ,0x01 ,0x00,
562 0x00 ,0x0e ,0x10 ,0x00 ,0x04 ,0x81 ,0x6f ,0x0b,
575 memset(&ipv4h, 0,
sizeof(
IPV4Hdr));
585 de = DetectFragBitsParse(
"!D");
597 ret = DetectFragBitsMatch(NULL, p, NULL, sm->
ctx);
610 static void FragBitsRegisterTests(
void)