85 static void DetectCsumRegisterTests(
void);
183 static int DetectCsumParseArg(
const char *key,
DetectCsumData *cd)
187 if (key[0] ==
'\"' && key[strlen(key) - 1] ==
'\"') {
192 str[strlen(key) - 2] =
'\0';
282 if (DetectCsumParseArg(csum_str, cd) == 0)
292 if (cd != NULL) DetectIPV4CsumFree(
de_ctx, cd);
293 if (sm != NULL)
SCFree(sm);
379 if (DetectCsumParseArg(csum_str, cd) == 0)
389 if (cd != NULL) DetectTCPV4CsumFree(
de_ctx, cd);
390 if (sm != NULL)
SCFree(sm);
476 if (DetectCsumParseArg(csum_str, cd) == 0)
486 if (cd != NULL) DetectTCPV6CsumFree(
de_ctx, cd);
487 if (sm != NULL)
SCFree(sm);
573 if (DetectCsumParseArg(csum_str, cd) == 0)
583 if (cd != NULL) DetectUDPV4CsumFree(
de_ctx, cd);
584 if (sm != NULL)
SCFree(sm);
670 if (DetectCsumParseArg(csum_str, cd) == 0)
673 sm->
ctx = (
void *)cd;
680 if (cd != NULL) DetectUDPV6CsumFree(
de_ctx, cd);
681 if (sm != NULL)
SCFree(sm);
765 if (DetectCsumParseArg(csum_str, cd) == 0)
775 if (cd != NULL) DetectICMPV4CsumFree(
de_ctx, cd);
776 if (sm != NULL)
SCFree(sm);
863 if (DetectCsumParseArg(csum_str, cd) == 0)
873 if (cd != NULL) DetectICMPV6CsumFree(
de_ctx, cd);
874 if (sm != NULL)
SCFree(sm);
895 #define TEST1(kwstr) {\
896 DetectEngineCtx *de_ctx = DetectEngineCtxInit();\
897 FAIL_IF_NULL(de_ctx);\
898 de_ctx->flags = DE_QUIET;\
900 Signature *s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:valid; sid:1;)");\
902 s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:invalid; sid:2;)");\
904 s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:vaLid; sid:3;)");\
906 s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:VALID; sid:4;)");\
908 s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:iNvaLid; sid:5;)");\
910 DetectEngineCtxFree(de_ctx);\
914 static int DetectCsumValidArgsTestParse01(
void)
927 #define TEST2(kwstr) { \
928 DetectEngineCtx *de_ctx = DetectEngineCtxInit();\
929 FAIL_IF_NULL(de_ctx);\
930 Signature *s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:vaid; sid:1;)");\
932 s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:invaalid; sid:2;)");\
934 s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:vaLiid; sid:3;)");\
936 s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:VALieD; sid:4;)");\
938 s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:iNvamid; sid:5;)");\
940 DetectEngineCtxFree(de_ctx);\
943 static int DetectCsumInvalidArgsTestParse02(
void)
956 #define TEST3(kwstr, kwtype) { \
957 DetectEngineCtx *de_ctx = DetectEngineCtxInit();\
958 FAIL_IF_NULL(de_ctx);\
959 Signature *s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:valid; sid:1;)");\
961 SigMatch *sm = DetectGetLastSMFromLists(s, (kwtype), -1);\
963 FAIL_IF_NULL(sm->ctx);\
964 FAIL_IF_NOT(((DetectCsumData *)sm->ctx)->valid == 1);\
965 s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any ("mystr(kwstr)"-csum:INVALID; sid:2;)");\
967 sm = DetectGetLastSMFromLists(s, (kwtype), -1);\
969 FAIL_IF_NULL(sm->ctx);\
970 FAIL_IF_NOT(((DetectCsumData *)sm->ctx)->valid == 0);\
971 DetectEngineCtxFree(de_ctx);\
974 static int DetectCsumValidArgsTestParse03(
void)
991 static int DetectCsumICMPV6Test01(
void)
1003 0x00, 0x30, 0x18, 0xa8, 0x7c, 0x23, 0x2c, 0x41,
1004 0x38, 0xa7, 0xea, 0xeb, 0x86, 0xdd, 0x60, 0x00,
1005 0x00, 0x00, 0x00, 0x40, 0x3c, 0x40, 0xad, 0xa1,
1006 0x09, 0x80, 0x00, 0x01, 0xd6, 0xf3, 0x20, 0x01,
1007 0xf4, 0xbe, 0xea, 0x3c, 0x00, 0x01, 0x00, 0x00,
1008 0x00, 0x00, 0x32, 0xb2, 0x00, 0x01, 0x32, 0xb2,
1009 0x09, 0x80, 0x20, 0x01, 0x00, 0x00, 0x3c, 0x00,
1010 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00,
1011 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00,
1012 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00,
1013 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00,
1014 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00,
1015 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00,
1016 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00,
1017 0x63, 0xc2, 0x00, 0x00, 0x00, 0x00 };
1021 memset(&
tv, 0,
sizeof(
tv));
1022 memset(&
dtv, 0,
sizeof(
dtv));
1033 "(icmpv6-csum:valid; sid:1;)");
1055 static void DetectCsumRegisterTests(
void)
1058 DetectCsumValidArgsTestParse01);
1060 DetectCsumInvalidArgsTestParse02);
1062 DetectCsumValidArgsTestParse03);
1065 DetectCsumICMPV6Test01);