-/* Copyright (C) 2012-2020 Open Information Security Foundation
+/* Copyright (C) 2012-2021 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
DetectEngineThreadCtx *det_ctx = NULL;
Signature *sig = NULL;
FILE *fd = NULL;
- int result = 0, r = 0;
+ int r = 0;
Packet *p = UTHBuildPacket((uint8_t *)"lalala", 6, IPPROTO_TCP);
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
HostInitConfig(HOST_QUIET);
memset(&th_v, 0, sizeof(th_v));
- if (de_ctx == NULL || p == NULL)
- goto end;
+ FAIL_IF_NULL(de_ctx);
+ FAIL_IF_NULL(p);
p->src.addr_data32[0] = UTHSetIPv4Address("10.0.0.1");
de_ctx->flags |= DE_QUIET;
fd = DetectIPRepGenerateCategoriesDummy();
r = SRepLoadCatFileFromFD(fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
fd = DetectIPRepGenerateNetworksDummy();
r = SRepLoadFileFromFD(de_ctx->srepCIDR_ctx, fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
- sig = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value badhost\"; iprep:any,BadHosts,>,1; sid:1;rev:1;)");
- if (sig == NULL) {
- goto end;
- }
+ sig = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value "
+ "badhost\"; iprep:any,BadHosts,>,1; sid:1;rev:1;)");
+ FAIL_IF_NULL(sig);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
p->alerts.cnt = 0;
p->action = 0;
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
- if (p->alerts.cnt != 1 || PACKET_TEST_ACTION(p, ACTION_DROP)) {
- goto end;
- }
- result = 1;
-end:
+ FAIL_IF(p->alerts.cnt != 1);
+ FAIL_IF(PACKET_TEST_ACTION(p, ACTION_DROP));
+
UTHFreePacket(p);
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
HostShutdown();
- return result;
+ PASS;
}
static int DetectIPRepTest02(void)
DetectEngineThreadCtx *det_ctx = NULL;
Signature *sig = NULL;
FILE *fd = NULL;
- int result = 0, r = 0;
+ int r = 0;
Packet *p = UTHBuildPacket((uint8_t *)"lalala", 6, IPPROTO_TCP);
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
HostInitConfig(HOST_QUIET);
memset(&th_v, 0, sizeof(th_v));
- if (de_ctx == NULL || p == NULL)
- goto end;
+ FAIL_IF_NULL(de_ctx);
+ FAIL_IF_NULL(p);
p->src.addr_data32[0] = UTHSetIPv4Address("10.0.0.1");
de_ctx->flags |= DE_QUIET;
fd = DetectIPRepGenerateCategoriesDummy();
r = SRepLoadCatFileFromFD(fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
fd = DetectIPRepGenerateNetworksDummy();
r = SRepLoadFileFromFD(de_ctx->srepCIDR_ctx, fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
- sig = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value badhost\"; iprep:src,BadHosts,>,1; sid:1; rev:1;)");
- if (sig == NULL) {
- goto end;
- }
+ sig = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value "
+ "badhost\"; iprep:src,BadHosts,>,1; sid:1; rev:1;)");
+ FAIL_IF_NULL(sig);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
p->alerts.cnt = 0;
p->action = 0;
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
- if (p->alerts.cnt != 1 || PACKET_TEST_ACTION(p, ACTION_DROP)) {
- goto end;
- }
+ FAIL_IF(p->alerts.cnt != 1);
+ FAIL_IF(PACKET_TEST_ACTION(p, ACTION_DROP));
- result = 1;
-end:
UTHFreePacket(p);
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
HostShutdown();
- return result;
+ PASS;
}
static int DetectIPRepTest03(void)
DetectEngineThreadCtx *det_ctx = NULL;
Signature *sig = NULL;
FILE *fd = NULL;
- int result = 0, r = 0;
+ int r = 0;
Packet *p = UTHBuildPacket((uint8_t *)"lalala", 6, IPPROTO_TCP);
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
HostInitConfig(HOST_QUIET);
memset(&th_v, 0, sizeof(th_v));
- if (de_ctx == NULL || p == NULL)
- goto end;
+ FAIL_IF_NULL(de_ctx);
+ FAIL_IF_NULL(p);
p->dst.addr_data32[0] = UTHSetIPv4Address("10.0.0.2");
de_ctx->flags |= DE_QUIET;
fd = DetectIPRepGenerateCategoriesDummy();
r = SRepLoadCatFileFromFD(fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
fd = DetectIPRepGenerateNetworksDummy();
r = SRepLoadFileFromFD(de_ctx->srepCIDR_ctx, fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
- sig = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value badhost\"; iprep:dst,BadHosts,>,1; sid:1; rev:1;)");
- if (sig == NULL) {
- goto end;
- }
+ sig = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value "
+ "badhost\"; iprep:dst,BadHosts,>,1; sid:1; rev:1;)");
+ FAIL_IF_NULL(sig);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
p->alerts.cnt = 0;
p->action = 0;
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
- if (p->alerts.cnt != 1 || PACKET_TEST_ACTION(p, ACTION_DROP)) {
- goto end;
- }
+ FAIL_IF(p->alerts.cnt != 1);
+ FAIL_IF(PACKET_TEST_ACTION(p, ACTION_DROP));
- result = 1;
-end:
UTHFreePacket(p);
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
HostShutdown();
- return result;
+ PASS;
}
static int DetectIPRepTest04(void)
DetectEngineThreadCtx *det_ctx = NULL;
Signature *sig = NULL;
FILE *fd = NULL;
- int result = 0, r = 0;
+ int r = 0;
Packet *p = UTHBuildPacket((uint8_t *)"lalala", 6, IPPROTO_TCP);
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
HostInitConfig(HOST_QUIET);
memset(&th_v, 0, sizeof(th_v));
- if (de_ctx == NULL || p == NULL)
- goto end;
+ FAIL_IF_NULL(de_ctx);
+ FAIL_IF_NULL(p);
p->src.addr_data32[0] = UTHSetIPv4Address("10.0.0.1");
p->dst.addr_data32[0] = UTHSetIPv4Address("10.0.0.2");
fd = DetectIPRepGenerateCategoriesDummy();
r = SRepLoadCatFileFromFD(fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
fd = DetectIPRepGenerateNetworksDummy();
r = SRepLoadFileFromFD(de_ctx->srepCIDR_ctx, fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
- sig = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value badhost\"; iprep:both,BadHosts,>,1; sid:1; rev:1;)");
- if (sig == NULL) {
- goto end;
- }
+ sig = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value "
+ "badhost\"; iprep:both,BadHosts,>,1; sid:1; rev:1;)");
+ FAIL_IF_NULL(sig);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
p->alerts.cnt = 0;
p->action = 0;
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
- if (p->alerts.cnt != 1 || PACKET_TEST_ACTION(p, ACTION_DROP)) {
- goto end;
- }
+ FAIL_IF(p->alerts.cnt != 1);
+ FAIL_IF(PACKET_TEST_ACTION(p, ACTION_DROP));
- result = 1;
-end:
UTHFreePacket(p);
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
HostShutdown();
- return result;
+ PASS;
}
static int DetectIPRepTest05(void)
DetectEngineThreadCtx *det_ctx = NULL;
Signature *sig = NULL;
FILE *fd = NULL;
- int result = 0, r = 0;
+ int r = 0;
Packet *p = UTHBuildPacket((uint8_t *)"lalala", 6, IPPROTO_TCP);
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
HostInitConfig(HOST_QUIET);
memset(&th_v, 0, sizeof(th_v));
- if (de_ctx == NULL || p == NULL)
- goto end;
+ FAIL_IF_NULL(de_ctx);
+ FAIL_IF_NULL(p);
p->src.addr_data32[0] = UTHSetIPv4Address("1.0.0.1");
de_ctx->flags |= DE_QUIET;
fd = DetectIPRepGenerateCategoriesDummy();
r = SRepLoadCatFileFromFD(fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
fd = DetectIPRepGenerateNetworksDummy();
r = SRepLoadFileFromFD(de_ctx->srepCIDR_ctx, fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
- sig = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value badhost\"; iprep:any,BadHosts,>,1; sid:1; rev:1;)");
- if (sig == NULL) {
- goto end;
- }
+ sig = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value "
+ "badhost\"; iprep:any,BadHosts,>,1; sid:1; rev:1;)");
+ FAIL_IF_NULL(sig);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
p->alerts.cnt = 0;
p->action = 0;
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
- if (p->alerts.cnt != 1 || PACKET_TEST_ACTION(p, ACTION_DROP)) {
- goto end;
- }
+ FAIL_IF(p->alerts.cnt != 0);
+ FAIL_IF(PACKET_TEST_ACTION(p, ACTION_DROP));
- result = 1;
-end:
UTHFreePacket(p);
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
HostShutdown();
- return result == 0;
+ PASS;
}
static int DetectIPRepTest06(void)
DetectEngineThreadCtx *det_ctx = NULL;
Signature *sig = NULL;
FILE *fd = NULL;
- int result = 0, r = 0;
+ int r = 0;
Packet *p = UTHBuildPacket((uint8_t *)"lalala", 6, IPPROTO_TCP);
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
HostInitConfig(HOST_QUIET);
memset(&th_v, 0, sizeof(th_v));
- if (de_ctx == NULL || p == NULL)
- goto end;
+ FAIL_IF_NULL(de_ctx);
+ FAIL_IF_NULL(p);
p->src.addr_data32[0] = UTHSetIPv4Address("1.0.0.1");
de_ctx->flags |= DE_QUIET;
fd = DetectIPRepGenerateCategoriesDummy();
r = SRepLoadCatFileFromFD(fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
- fd = DetectIPRepGenerateNetworksDummy();
+ fd = DetectIPRepGenerateNetworksDummy2();
r = SRepLoadFileFromFD(de_ctx->srepCIDR_ctx, fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
- sig = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value badhost\"; iprep:any,BadHosts,>,1; sid:1; rev:1;)");
- if (sig == NULL) {
- goto end;
- }
+ sig = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value "
+ "badhost\"; iprep:any,BadHosts,>,1; sid:1; rev:1;)");
+ FAIL_IF_NULL(sig);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
p->alerts.cnt = 0;
p->action = 0;
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
- if (p->alerts.cnt != 1 || PACKET_TEST_ACTION(p, ACTION_DROP)) {
- goto end;
- }
+ FAIL_IF(p->alerts.cnt != 1);
+ FAIL_IF(PACKET_TEST_ACTION(p, ACTION_DROP));
- result = 1;
-end:
UTHFreePacket(p);
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
HostShutdown();
- return result == 0;
+ PASS;
}
static int DetectIPRepTest07(void)
DetectEngineThreadCtx *det_ctx = NULL;
Signature *sig = NULL;
FILE *fd = NULL;
- int result = 0, r = 0;
+ int r = 0;
Packet *p = UTHBuildPacket((uint8_t *)"lalala", 6, IPPROTO_TCP);
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
HostInitConfig(HOST_QUIET);
memset(&th_v, 0, sizeof(th_v));
- if (de_ctx == NULL || p == NULL)
- goto end;
+ FAIL_IF_NULL(de_ctx);
+ FAIL_IF_NULL(p);
p->dst.addr_data32[0] = UTHSetIPv4Address("1.0.0.2");
de_ctx->flags |= DE_QUIET;
fd = DetectIPRepGenerateCategoriesDummy();
r = SRepLoadCatFileFromFD(fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
- fd = DetectIPRepGenerateNetworksDummy();
+ fd = DetectIPRepGenerateNetworksDummy2();
r = SRepLoadFileFromFD(de_ctx->srepCIDR_ctx, fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
- sig = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value badhost\"; iprep:any,BadHosts,>,1; sid:1; rev:1;)");
- if (sig == NULL) {
- goto end;
- }
+ sig = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value "
+ "badhost\"; iprep:any,BadHosts,>,1; sid:1; rev:1;)");
+ FAIL_IF_NULL(sig);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
p->alerts.cnt = 0;
p->action = 0;
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
- if (p->alerts.cnt != 1 || PACKET_TEST_ACTION(p, ACTION_DROP)) {
- goto end;
- }
+ FAIL_IF(p->alerts.cnt != 1);
+ FAIL_IF(PACKET_TEST_ACTION(p, ACTION_DROP));
- result = 1;
-end:
UTHFreePacket(p);
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
HostShutdown();
- return result == 0;
+ PASS;
}
static int DetectIPRepTest08(void)
DetectEngineThreadCtx *det_ctx = NULL;
Signature *sig = NULL;
FILE *fd = NULL;
- int result = 0, r = 0;
+ int r = 0;
Packet *p = UTHBuildPacket((uint8_t *)"lalala", 6, IPPROTO_TCP);
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
HostInitConfig(HOST_QUIET);
memset(&th_v, 0, sizeof(th_v));
- if (de_ctx == NULL || p == NULL)
- goto end;
+ FAIL_IF_NULL(de_ctx);
+ FAIL_IF_NULL(p);
p->src.addr_data32[0] = UTHSetIPv4Address("1.0.0.1");
p->dst.addr_data32[0] = UTHSetIPv4Address("1.0.0.2");
fd = DetectIPRepGenerateCategoriesDummy();
r = SRepLoadCatFileFromFD(fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
fd = DetectIPRepGenerateNetworksDummy();
r = SRepLoadFileFromFD(de_ctx->srepCIDR_ctx, fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
- sig = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value badhost\"; iprep:any,BadHosts,>,1; sid:1; rev:1;)");
- if (sig == NULL) {
- goto end;
- }
+ sig = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (msg:\"IPREP High value "
+ "badhost\"; iprep:any,BadHosts,>,1; sid:1; rev:1;)");
+ FAIL_IF_NULL(sig);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
p->alerts.cnt = 0;
p->action = 0;
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
- if (p->alerts.cnt != 1 || PACKET_TEST_ACTION(p, ACTION_DROP)) {
- goto end;
- }
+ FAIL_IF(p->alerts.cnt != 0);
+ FAIL_IF(PACKET_TEST_ACTION(p, ACTION_DROP));
- result = 1;
-end:
UTHFreePacket(p);
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
HostShutdown();
- return result == 0;
+ PASS;
}
static int DetectIPRepTest09(void)
DetectEngineThreadCtx *det_ctx = NULL;
Signature *sig = NULL;
FILE *fd = NULL;
- int result = 0, r = 0;
+ int r = 0;
Packet *p = UTHBuildPacket((uint8_t *)"lalala", 6, IPPROTO_TCP);
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
HostInitConfig(HOST_QUIET);
memset(&th_v, 0, sizeof(th_v));
- if (de_ctx == NULL || p == NULL)
- goto end;
+ FAIL_IF_NULL(de_ctx);
+ FAIL_IF_NULL(p);
p->src.addr_data32[0] = UTHSetIPv4Address("192.168.0.1");
p->dst.addr_data32[0] = UTHSetIPv4Address("192.168.0.2");
fd = DetectIPRepGenerateCategoriesDummy2();
r = SRepLoadCatFileFromFD(fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
fd = DetectIPRepGenerateNetworksDummy2();
r = SRepLoadFileFromFD(de_ctx->srepCIDR_ctx, fd);
- if (r < 0) {
- goto end;
- }
+ FAIL_IF(r < 0);
- sig = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any (msg:\"test\"; iprep:src,BadHosts,>,9; sid:1; rev:1;)");
- if (sig == NULL) {
- goto end;
- }
+ sig = DetectEngineAppendSig(de_ctx,
+ "alert tcp any any -> any any (msg:\"test\"; iprep:src,BadHosts,>,9; sid:1; rev:1;)");
+ FAIL_IF_NULL(sig);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
p->alerts.cnt = 0;
p->action = 0;
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
- if (p->alerts.cnt != 1 || PACKET_TEST_ACTION(p, ACTION_DROP)) {
- goto end;
- }
+ FAIL_IF(p->alerts.cnt != 1);
+ FAIL_IF(PACKET_TEST_ACTION(p, ACTION_DROP));
- result = 1;
-end:
UTHFreePacket(p);
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
HostShutdown();
- return result;
+ PASS;
}
/**
UtRegisterTest("DetectIPRepTest08", DetectIPRepTest08);
UtRegisterTest("DetectIPRepTest09", DetectIPRepTest09);
}
-#endif /* UNITTESTS */
\ No newline at end of file
+#endif /* UNITTESTS */