48 #define PARSE_REGEX "^\\s*(?:([\\+\\*!]))?\\s*([SAPRFU120CE\\+\\*!]+)(?:\\s*,\\s*([SAPRFU12CE]+))?\\s*$"
55 #define MODIFIER_NOT 1
56 #define MODIFIER_PLUS 2
57 #define MODIFIER_ANY 3
66 static bool PrefilterTcpFlagsIsPrefilterable(
const Signature *s);
69 static void FlagsRegisterTests(
void);
94 static inline int FlagsMatch(
const uint8_t pflags,
const uint8_t modifier,
95 const uint8_t dflags,
const uint8_t iflags)
97 if (!dflags && pflags) {
105 const uint8_t
flags = pflags & iflags;
109 if ((
flags & dflags) > 0) {
115 if (((
flags & dflags) == dflags)) {
121 if ((
flags & dflags) != dflags) {
128 if (
flags == dflags) {
155 if (!(PacketIsTCP(p))) {
160 const TCPHdr *tcph = PacketGetTCP(p);
163 return FlagsMatch(
flags,
de->modifier,
de->flags,
de->ignored_flags);
179 int found = 0, ignore = 0;
187 pcre2_match_data *match = NULL;
189 SCLogDebug(
"input '%s', pcre said %d", rawstr, ret);
195 size_t pcre2len =
sizeof(arg1);
198 SCLogError(
"pcre2_substring_copy_bynumber failed");
202 pcre2len =
sizeof(arg2);
203 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)arg2, &pcre2len);
205 SCLogError(
"pcre2_substring_copy_bynumber failed");
210 pcre2len =
sizeof(arg3);
213 SCLogError(
"pcre2_substring_copy_bynumber failed");
217 SCLogDebug(
"args '%s', '%s', '%s'", arg1, arg2, arg3);
219 if (strlen(arg2) == 0) {
227 de->ignored_flags = 0xff;
231 while (*ptr !=
'\0') {
300 if (strlen(arg2) > 0) {
302 while (*ptr !=
'\0') {
352 if (
de->modifier != 0) {
354 " one modifier at a time");
361 if (
de->modifier != 0) {
363 " one modifier at a time");
370 if (
de->modifier != 0) {
372 " one modifier at a time");
389 if (strlen(arg3) > 0) {
392 while (*ptr !=
'\0') {
456 pcre2_match_data_free(match);
457 SCLogDebug(
"found %"PRId32
" ignore %"PRId32
"", found, ignore);
465 pcre2_match_data_free(match);
486 de = DetectFlagsParse(rawstr);
558 if (!(PacketIsTCP(p))) {
563 if (!PrefilterPacketHeaderExtraMatch(
ctx, p))
566 const TCPHdr *tcph = PacketGetTCP(p);
568 if (FlagsMatch(
flags,
ctx->v1.u8[0],
ctx->v1.u8[1],
ctx->v1.u8[2]))
571 PrefilterAddSids(&det_ctx->
pmq,
ctx->sigs_array,
ctx->sigs_cnt);
599 PrefilterPacketFlagsSet, PrefilterPacketFlagsCompare, PrefilterPacketFlagsMatch);
602 static bool PrefilterTcpFlagsIsPrefilterable(
const Signature *s)
625 static int FlagsTestParse01 (
void)
630 DetectFlagsFree(NULL,
de);
640 static int FlagsTestParse02 (
void)
643 de = DetectFlagsParse(
"G");
645 DetectFlagsFree(NULL,
de);
658 static int FlagsTestParse03 (
void)
671 memset(&ipv4h, 0,
sizeof(
IPV4Hdr));
672 memset(&tcph, 0,
sizeof(
TCPHdr));
678 de = DetectFlagsParse(
"AP+");
690 ret = DetectFlagsMatch(NULL, p, NULL, sm->
ctx);
712 static int FlagsTestParse04 (
void)
725 memset(&ipv4h, 0,
sizeof(
IPV4Hdr));
726 memset(&tcph, 0,
sizeof(
TCPHdr));
732 de = DetectFlagsParse(
"A");
744 ret = DetectFlagsMatch(NULL, p, NULL, sm->
ctx);
767 static int FlagsTestParse05 (
void)
780 memset(&ipv4h, 0,
sizeof(
IPV4Hdr));
781 memset(&tcph, 0,
sizeof(
TCPHdr));
787 de = DetectFlagsParse(
"+AP,SR");
799 ret = DetectFlagsMatch(NULL, p, NULL, sm->
ctx);
822 static int FlagsTestParse06 (
void)
835 memset(&ipv4h, 0,
sizeof(
IPV4Hdr));
836 memset(&tcph, 0,
sizeof(
TCPHdr));
842 de = DetectFlagsParse(
"+AP,UR");
854 ret = DetectFlagsMatch(NULL, p, NULL, sm->
ctx);
876 static int FlagsTestParse07 (
void)
889 memset(&ipv4h, 0,
sizeof(
IPV4Hdr));
890 memset(&tcph, 0,
sizeof(
TCPHdr));
896 de = DetectFlagsParse(
"*AP");
908 ret = DetectFlagsMatch(NULL, p, NULL, sm->
ctx);
931 static int FlagsTestParse08 (
void)
944 memset(&ipv4h, 0,
sizeof(
IPV4Hdr));
945 memset(&tcph, 0,
sizeof(
TCPHdr));
951 de = DetectFlagsParse(
"*SA");
963 ret = DetectFlagsMatch(NULL, p, NULL, sm->
ctx);
985 static int FlagsTestParse09 (
void)
998 memset(&ipv4h, 0,
sizeof(
IPV4Hdr));
999 memset(&tcph, 0,
sizeof(
TCPHdr));
1005 de = DetectFlagsParse(
"!PA");
1017 ret = DetectFlagsMatch(NULL, p, NULL, sm->
ctx);
1039 static int FlagsTestParse10 (
void)
1052 memset(&ipv4h, 0,
sizeof(
IPV4Hdr));
1053 memset(&tcph, 0,
sizeof(
TCPHdr));
1059 de = DetectFlagsParse(
"!AP");
1071 ret = DetectFlagsMatch(NULL, p, NULL, sm->
ctx);
1093 static int FlagsTestParse11 (
void)
1106 memset(&ipv4h, 0,
sizeof(
IPV4Hdr));
1107 memset(&tcph, 0,
sizeof(
TCPHdr));
1113 de = DetectFlagsParse(
"*AP,SR");
1125 ret = DetectFlagsMatch(NULL, p, NULL, sm->
ctx);
1148 static int FlagsTestParse12 (
void)
1161 memset(&ipv4h, 0,
sizeof(
IPV4Hdr));
1162 memset(&tcph, 0,
sizeof(
TCPHdr));
1168 de = DetectFlagsParse(
"0");
1170 if (
de == NULL ||
de->flags != 0) {
1171 printf(
"de setup: ");
1182 ret = DetectFlagsMatch(NULL, p, NULL, sm->
ctx);
1205 static int FlagsTestParse13 (
void)
1208 de = DetectFlagsParse(
"+S*");
1210 DetectFlagsFree(NULL,
de);
1223 static int FlagsTestParse14(
void)
1227 DetectFlagsFree(NULL,
de);
1234 static int FlagsTestParse15(
void)
1247 memset(&ipv4h, 0,
sizeof(
IPV4Hdr));
1248 memset(&tcph, 0,
sizeof(
TCPHdr));
1254 de = DetectFlagsParse(
"EC+");
1266 ret = DetectFlagsMatch(NULL, p, NULL, sm->
ctx);
1286 static int FlagsTestParse16(
void)
1299 memset(&ipv4h, 0,
sizeof(
IPV4Hdr));
1300 memset(&tcph, 0,
sizeof(
TCPHdr));
1306 de = DetectFlagsParse(
"EC*");
1318 ret = DetectFlagsMatch(NULL, p, NULL, sm->
ctx);
1341 static int FlagsTestParse17(
void)
1354 memset(&ipv4h, 0,
sizeof(
IPV4Hdr));
1355 memset(&tcph, 0,
sizeof(
TCPHdr));
1361 de = DetectFlagsParse(
"EC+");
1373 ret = DetectFlagsMatch(NULL, p, NULL, sm->
ctx);
1396 static void FlagsRegisterTests(
void)