42 #define DETECT_CSUM_VALID "valid"
43 #define DETECT_CSUM_INVALID "invalid"
94 static void DetectCsumRegisterTests(
void);
192 static int DetectCsumParseArg(
const char *key,
DetectCsumData *cd)
196 if (key[0] ==
'\"' && key[strlen(key) - 1] ==
'\"') {
201 str[strlen(key) - 2] =
'\0';
291 if (DetectCsumParseArg(csum_str, cd) == 0)
301 if (cd != NULL) DetectIPV4CsumFree(
de_ctx, cd);
302 if (sm != NULL)
SCFree(sm);
388 if (DetectCsumParseArg(csum_str, cd) == 0)
398 if (cd != NULL) DetectTCPV4CsumFree(
de_ctx, cd);
399 if (sm != NULL)
SCFree(sm);
485 if (DetectCsumParseArg(csum_str, cd) == 0)
495 if (cd != NULL) DetectTCPV6CsumFree(
de_ctx, cd);
496 if (sm != NULL)
SCFree(sm);
582 if (DetectCsumParseArg(csum_str, cd) == 0)
592 if (cd != NULL) DetectUDPV4CsumFree(
de_ctx, cd);
593 if (sm != NULL)
SCFree(sm);
679 if (DetectCsumParseArg(csum_str, cd) == 0)
682 sm->
ctx = (
void *)cd;
689 if (cd != NULL) DetectUDPV6CsumFree(
de_ctx, cd);
690 if (sm != NULL)
SCFree(sm);
774 if (DetectCsumParseArg(csum_str, cd) == 0)
784 if (cd != NULL) DetectICMPV4CsumFree(
de_ctx, cd);
785 if (sm != NULL)
SCFree(sm);
872 if (DetectCsumParseArg(csum_str, cd) == 0)
882 if (cd != NULL) DetectICMPV6CsumFree(
de_ctx, cd);
883 if (sm != NULL)
SCFree(sm);
907 #define TEST1(kwstr) {\
908 DetectEngineCtx *de_ctx = DetectEngineCtxInit();\
909 FAIL_IF_NULL(de_ctx);\
910 de_ctx->flags = DE_QUIET;\
912 Signature *s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:valid; sid:1;)");\
914 s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:invalid; sid:2;)");\
916 s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:vaLid; sid:3;)");\
918 s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:VALID; sid:4;)");\
920 s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:iNvaLid; sid:5;)");\
922 DetectEngineCtxFree(de_ctx);\
926 static int DetectCsumValidArgsTestParse01(
void)
939 #define TEST2(kwstr) \
941 DetectEngineCtx *de_ctx = DetectEngineCtxInit(); \
942 FAIL_IF_NULL(de_ctx); \
943 Signature *s = DetectEngineAppendSig( \
944 de_ctx, "alert ip any any -> any any (" mystr(kwstr) "-csum:xxxx; sid:1;)"); \
946 s = DetectEngineAppendSig( \
947 de_ctx, "alert ip any any -> any any (" mystr(kwstr) "-csum:xxxxxxxx; sid:2;)"); \
949 s = DetectEngineAppendSig( \
950 de_ctx, "alert ip any any -> any any (" mystr(kwstr) "-csum:xxxxxx; sid:3;)"); \
952 s = DetectEngineAppendSig( \
953 de_ctx, "alert ip any any -> any any (" mystr(kwstr) "-csum:XXXXXX; sid:4;)"); \
955 s = DetectEngineAppendSig( \
956 de_ctx, "alert ip any any -> any any (" mystr(kwstr) "-csum:XxXxXxX; sid:5;)"); \
958 DetectEngineCtxFree(de_ctx); \
961 static int DetectCsumInvalidArgsTestParse02(
void)
974 #define TEST3(kwstr, kwtype) { \
975 DetectEngineCtx *de_ctx = DetectEngineCtxInit();\
976 FAIL_IF_NULL(de_ctx);\
977 Signature *s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:valid; sid:1;)");\
979 SigMatch *sm = DetectGetLastSMFromLists(s, (kwtype), -1);\
981 FAIL_IF_NULL(sm->ctx);\
982 FAIL_IF_NOT(((DetectCsumData *)sm->ctx)->valid == 1);\
983 s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:INVALID; sid:2;)");\
985 sm = DetectGetLastSMFromLists(s, (kwtype), -1);\
987 FAIL_IF_NULL(sm->ctx);\
988 FAIL_IF_NOT(((DetectCsumData *)sm->ctx)->valid == 0);\
989 DetectEngineCtxFree(de_ctx);\
992 static int DetectCsumValidArgsTestParse03(
void)
1008 static int DetectCsumICMPV6Test01(
void)
1020 0x00, 0x30, 0x18, 0xa8, 0x7c, 0x23, 0x2c, 0x41,
1021 0x38, 0xa7, 0xea, 0xeb, 0x86, 0xdd, 0x60, 0x00,
1022 0x00, 0x00, 0x00, 0x40, 0x3c, 0x40, 0xad, 0xa1,
1023 0x09, 0x80, 0x00, 0x01, 0xd6, 0xf3, 0x20, 0x01,
1024 0xf4, 0xbe, 0xea, 0x3c, 0x00, 0x01, 0x00, 0x00,
1025 0x00, 0x00, 0x32, 0xb2, 0x00, 0x01, 0x32, 0xb2,
1026 0x09, 0x80, 0x20, 0x01, 0x00, 0x00, 0x3c, 0x00,
1027 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00,
1028 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00,
1029 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00,
1030 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00,
1031 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00,
1032 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00,
1033 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00,
1034 0x63, 0xc2, 0x00, 0x00, 0x00, 0x00 };
1038 memset(&
tv, 0,
sizeof(
tv));
1039 memset(&
dtv, 0,
sizeof(
dtv));
1050 "(icmpv6-csum:valid; sid:1;)");
1072 static void DetectCsumRegisterTests(
void)
1075 DetectCsumValidArgsTestParse01);
1077 DetectCsumInvalidArgsTestParse02);
1079 DetectCsumValidArgsTestParse03);
1082 DetectCsumICMPV6Test01);