{
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
+ FAIL_IF_NULL(p);
Signature *s = NULL;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx;
- int result = 0;
IPV4Hdr ip4h;
memset(&th_v, 0, sizeof(th_v));
p->ip4h = &ip4h;
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
- s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"l3proto ipv4\"; l3_proto:ipv4; sid:1;)");
- if (s == NULL) {
- goto end;
- }
+ s = DetectEngineAppendSig(
+ de_ctx, "alert ip any any -> any any (msg:\"l3proto ipv4\"; l3_proto:ipv4; sid:1;)");
+ FAIL_IF_NULL(s);
- s = s->next = SigInit(de_ctx,"alert ip any any -> any any (msg:\"l3proto ipv6\"; l3_proto:ipv6; sid:2;)");
- if (s == NULL) {
- goto end;
- }
+ s = DetectEngineAppendSig(
+ de_ctx, "alert ip any any -> any any (msg:\"l3proto ipv6\"; l3_proto:ipv6; sid:2;)");
+ FAIL_IF_NULL(s);
- s = s->next = SigInit(de_ctx,"alert ip any any -> any any (msg:\"l3proto ip4\"; l3_proto:ip4; sid:3;)");
- if (s == NULL) {
- goto end;
- }
+ s = DetectEngineAppendSig(
+ de_ctx, "alert ip any any -> any any (msg:\"l3proto ip4\"; l3_proto:ip4; sid:3;)");
+ FAIL_IF_NULL(s);
- s = s->next = SigInit(de_ctx,"alert ip any any -> any any (msg:\"l3proto ip6\"; l3_proto:ip6; sid:2;)");
- if (s == NULL) {
- goto end;
- }
+ s = DetectEngineAppendSig(
+ de_ctx, "alert ip any any -> any any (msg:\"l3proto ip6\"; l3_proto:ip6; sid:4;)");
+ FAIL_IF_NULL(s);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
- if (PacketAlertCheck(p, 1) == 0) {
- printf("sid 1 did not alert, but should have: ");
- goto cleanup;
- } else if (PacketAlertCheck(p, 2)) {
- printf("sid 2 alerted, but should not have: ");
- goto cleanup;
- } else if (PacketAlertCheck(p, 3) == 0) {
- printf("sid 3 did not alert, but should have: ");
- goto cleanup;
- } else if (PacketAlertCheck(p, 4)) {
- printf("sid 4 alerted, but should not have: ");
- goto cleanup;
- }
-
- result = 1;
-
-cleanup:
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
+ FAIL_IF_NOT(PacketAlertCheck(p, 1));
+ FAIL_IF(PacketAlertCheck(p, 2));
+ FAIL_IF_NOT(PacketAlertCheck(p, 3));
+ FAIL_IF(PacketAlertCheck(p, 4));
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
-end:
SCFree(p);
- return result;
+
+ PASS;
}
/**
{
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
+ FAIL_IF_NULL(p);
Signature *s = NULL;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx;
- int result = 0;
IPV6Hdr ip6h;
memset(&th_v, 0, sizeof(th_v));
p->ip6h = &ip6h;
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
- s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"l3proto ipv4\"; l3_proto:ipv4; sid:1;)");
- if (s == NULL) {
- goto end;
- }
+ s = DetectEngineAppendSig(
+ de_ctx, "alert ip any any -> any any (msg:\"l3proto ipv4\"; l3_proto:ipv4; sid:1;)");
+ FAIL_IF_NULL(s);
- s = s->next = SigInit(de_ctx,"alert ip any any -> any any (msg:\"l3proto ipv6\"; l3_proto:ipv6; sid:2;)");
- if (s == NULL) {
- goto end;
- }
+ s = DetectEngineAppendSig(
+ de_ctx, "alert ip any any -> any any (msg:\"l3proto ipv6\"; l3_proto:ipv6; sid:2;)");
+ FAIL_IF_NULL(s);
- s = s->next = SigInit(de_ctx,"alert ip any any -> any any (msg:\"l3proto ip4\"; l3_proto:ip4; sid:3;)");
- if (s == NULL) {
- goto end;
- }
+ s = DetectEngineAppendSig(
+ de_ctx, "alert ip any any -> any any (msg:\"l3proto ip4\"; l3_proto:ip4; sid:3;)");
+ FAIL_IF_NULL(s);
- s = s->next = SigInit(de_ctx,"alert ip any any -> any any (msg:\"l3proto ip6\"; l3_proto:ip6; sid:4;)");
- if (s == NULL) {
- goto end;
- }
+ s = DetectEngineAppendSig(
+ de_ctx, "alert ip any any -> any any (msg:\"l3proto ip6\"; l3_proto:ip6; sid:4;)");
+ FAIL_IF_NULL(s);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
- if (PacketAlertCheck(p, 1)) {
- printf("sid 1 alerted, but should not have: ");
- goto cleanup;
- } else if (PacketAlertCheck(p, 2) == 0) {
- printf("sid 2 did not alert, but should have: ");
- goto cleanup;
- } else if (PacketAlertCheck(p, 3)) {
- printf("sid 3 alerted, but should not have: ");
- goto cleanup;
- } else if (PacketAlertCheck(p, 4) == 0) {
- printf("sid 4 did not alert, but should have: ");
- goto cleanup;
- }
-
- result = 1;
-
-cleanup:
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
+ FAIL_IF(PacketAlertCheck(p, 1));
+ FAIL_IF_NOT(PacketAlertCheck(p, 2));
+ FAIL_IF(PacketAlertCheck(p, 3));
+ FAIL_IF_NOT(PacketAlertCheck(p, 4));
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
-end:
SCFree(p);
- return result;
+
+ PASS;
}
/**
{
Packet *p = PacketGetFromAlloc();
- if (unlikely(p == NULL))
- return 0;
+ FAIL_IF_NULL(p);
Signature *s = NULL;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx;
- int result = 0;
IPV6Hdr ip6h;
memset(&th_v, 0, sizeof(th_v));
p->ip6h = &ip6h;
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
- s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"l3proto ipv4 and ip_proto udp\"; l3_proto:ipv4; ip_proto:17; sid:1;)");
- if (s == NULL) {
- goto end;
- }
+ s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any (msg:\"l3proto ipv4 and "
+ "ip_proto udp\"; l3_proto:ipv4; ip_proto:17; sid:1;)");
+ FAIL_IF_NULL(s);
- s = s->next = SigInit(de_ctx,"alert ip any any -> any any (msg:\"l3proto ipv6 and ip_proto udp\"; l3_proto:ipv6; ip_proto:17; sid:2;)");
- if (s == NULL) {
- goto end;
- }
+ s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any (msg:\"l3proto ipv6 and "
+ "ip_proto udp\"; l3_proto:ipv6; ip_proto:17; sid:2;)");
+ FAIL_IF_NULL(s);
- s = s->next = SigInit(de_ctx,"alert ip any any -> any any (msg:\"l3proto ip4 and ip_proto tcp\"; l3_proto:ipv4; ip_proto:6; sid:3;)");
- if (s == NULL) {
- goto end;
- }
+ s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any (msg:\"l3proto ip4 and ip_proto "
+ "tcp\"; l3_proto:ipv4; ip_proto:6; sid:3;)");
+ FAIL_IF_NULL(s);
- s = s->next = SigInit(de_ctx,"alert ip any any -> any any (msg:\"l3proto ipv6 and ip_proto tcp\"; l3_proto:ipv6; ip_proto:6; sid:4;)");
- if (s == NULL) {
- goto end;
- }
+ s = DetectEngineAppendSig(de_ctx, "alert ip any any -> any any (msg:\"l3proto ipv6 and "
+ "ip_proto tcp\"; l3_proto:ipv6; ip_proto:6; sid:4;)");
+ FAIL_IF_NULL(s);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
- if (PacketAlertCheck(p, 1)) {
- printf("sid 1 alerted, but should not have: ");
- goto cleanup;
- } else if (PacketAlertCheck(p, 2)) {
- printf("sid 2 alerted, but should not have: ");
- goto cleanup;
- } else if (PacketAlertCheck(p, 3)) {
- printf("sid 3 alerted, but should not have: ");
- goto cleanup;
- } else if (PacketAlertCheck(p, 4) == 0) {
- printf("sid 4 did not alert, but should have: ");
- goto cleanup;
- }
-
- result = 1;
-
-cleanup:
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
+ FAIL_IF(PacketAlertCheck(p, 1));
+ FAIL_IF(PacketAlertCheck(p, 2));
+ FAIL_IF(PacketAlertCheck(p, 3));
+ FAIL_IF_NOT(PacketAlertCheck(p, 4));
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
-end:
SCFree(p);
- return result;
+
+ PASS;
}
/**