Supress usage of Packet declaration in tests.

For convenience, a massive usage of 'Packet p;' declaration has
been done in the tests function. Although this was completely
legal, this is not possible anymore because of the new Packet
allocation structure. This massive patch modifies all suricata
files to use a SCMalloc allocated pointer to Packet instead.

This patch has been done using coccinelle (http://coccinelle.lip6.fr)
which is a semantic patching tool. This ensures that things like call
to SCFree() should have not been forget because the semantic patch
explicitly forces the call to SCFree(p) before each return. With this
patch all unittests are running fine with a small and a big default
packet size.
remotes/origin/master-1.1.x
Eric Leblond 16 years ago committed by Victor Julien
parent 156b202597
commit 1db4aadd16

@ -756,44 +756,58 @@ static int Unified2Test01 (void) {
0x05, 0xb4, 0x04, 0x02, 0x08, 0x0a, 0x00, 0x1c,
0x28, 0x81, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03,
0x03, 0x06};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
int ret;
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&tv, 0, sizeof(ThreadVars));
memset(&pq, 0, sizeof(PacketQueue));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
p.alerts.cnt++;
p.alerts.alerts[p.alerts.cnt-1].sid = 1;
p.alerts.alerts[p.alerts.cnt-1].gid = 1;
p.alerts.alerts[p.alerts.cnt-1].rev = 1;
p.pktlen = sizeof(raw_ipv4_tcp);
p->alerts.cnt++;
p->alerts.alerts[p->alerts.cnt-1].sid = 1;
p->alerts.alerts[p->alerts.cnt-1].gid = 1;
p->alerts.alerts[p->alerts.cnt-1].rev = 1;
p->pktlen = sizeof(raw_ipv4_tcp);
FlowInitConfig(FLOW_QUIET);
DecodeEthernet(&tv, &dtv, &p, raw_ipv4_tcp, sizeof(raw_ipv4_tcp), &pq);
DecodeEthernet(&tv, &dtv, p, raw_ipv4_tcp, sizeof(raw_ipv4_tcp), &pq);
FlowShutdown();
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL)
if (oc == NULL) {
SCFree(p);
return 0;
}
lf = (LogFileCtx *)oc->data;
if(lf == NULL)
if(lf == NULL) {
SCFree(p);
return 0;
}
ret = Unified2AlertThreadInit(&tv, oc, &data);
if(ret == TM_ECODE_FAILED)
if(ret == TM_ECODE_FAILED) {
SCFree(p);
return 0;
ret = Unified2Alert(&tv, &p, data, &pq, NULL);
if(ret == TM_ECODE_FAILED)
}
ret = Unified2Alert(&tv, p, data, &pq, NULL);
if(ret == TM_ECODE_FAILED) {
SCFree(p);
return 0;
}
ret = Unified2AlertThreadDeinit(&tv, data);
if(ret == -1)
if(ret == -1) {
SCFree(p);
return 0;
}
Unified2AlertDeInitCtx(oc);
SCFree(p);
return 1;
}
@ -825,44 +839,58 @@ static int Unified2Test02 (void) {
0x00, 0x00, 0x02, 0x04, 0x05, 0xa0, 0x04, 0x02,
0x08, 0x0a, 0x00, 0x0a, 0x22, 0xa8, 0x00, 0x00,
0x00, 0x00, 0x01, 0x03, 0x03, 0x05 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
int ret;
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&tv, 0, sizeof(ThreadVars));
memset(&pq, 0, sizeof(PacketQueue));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
p.alerts.cnt++;
p.alerts.alerts[p.alerts.cnt-1].sid = 1;
p.alerts.alerts[p.alerts.cnt-1].gid = 1;
p.alerts.alerts[p.alerts.cnt-1].rev = 1;
p.pktlen = sizeof(raw_ipv6_tcp);
p->alerts.cnt++;
p->alerts.alerts[p->alerts.cnt-1].sid = 1;
p->alerts.alerts[p->alerts.cnt-1].gid = 1;
p->alerts.alerts[p->alerts.cnt-1].rev = 1;
p->pktlen = sizeof(raw_ipv6_tcp);
FlowInitConfig(FLOW_QUIET);
DecodeEthernet(&tv, &dtv, &p, raw_ipv6_tcp, sizeof(raw_ipv6_tcp), &pq);
DecodeEthernet(&tv, &dtv, p, raw_ipv6_tcp, sizeof(raw_ipv6_tcp), &pq);
FlowShutdown();
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL)
if (oc == NULL) {
SCFree(p);
return 0;
}
lf = (LogFileCtx *)oc->data;
if(lf == NULL)
if(lf == NULL) {
SCFree(p);
return 0;
}
ret = Unified2AlertThreadInit(&tv, oc, &data);
if(ret == -1)
if(ret == -1) {
SCFree(p);
return 0;
ret = Unified2Alert(&tv, &p, data, &pq, NULL);
if(ret == TM_ECODE_FAILED)
}
ret = Unified2Alert(&tv, p, data, &pq, NULL);
if(ret == TM_ECODE_FAILED) {
SCFree(p);
return 0;
}
ret = Unified2AlertThreadDeinit(&tv, data);
if(ret == -1)
if(ret == -1) {
SCFree(p);
return 0;
}
Unified2AlertDeInitCtx(oc);
SCFree(p);
return 1;
}
@ -900,41 +928,54 @@ static int Unified2Test03 (void) {
0x69, 0x6e, 0x67, 0x2e, 0x66, 0x72, 0x65, 0x65,
0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x65, 0x74,
0x0d, 0x0a};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
int ret;
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&tv, 0, sizeof(ThreadVars));
memset(&pq, 0, sizeof(PacketQueue));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
p.alerts.cnt++;
p.alerts.alerts[p.alerts.cnt-1].sid = 1;
p.alerts.alerts[p.alerts.cnt-1].gid = 1;
p.alerts.alerts[p.alerts.cnt-1].rev = 1;
p.pktlen = sizeof(raw_gre);
p->alerts.cnt++;
p->alerts.alerts[p->alerts.cnt-1].sid = 1;
p->alerts.alerts[p->alerts.cnt-1].gid = 1;
p->alerts.alerts[p->alerts.cnt-1].rev = 1;
p->pktlen = sizeof(raw_gre);
FlowInitConfig(FLOW_QUIET);
DecodeEthernet(&tv, &dtv, &p, raw_gre, sizeof(raw_gre), &pq);
DecodeEthernet(&tv, &dtv, p, raw_gre, sizeof(raw_gre), &pq);
FlowShutdown();
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL)
if (oc == NULL) {
SCFree(p);
return 0;
}
lf = (LogFileCtx *)oc->data;
if(lf == NULL)
if(lf == NULL) {
SCFree(p);
return 0;
}
ret = Unified2AlertThreadInit(&tv, oc, &data);
if(ret == -1)
if(ret == -1) {
SCFree(p);
return 0;
ret = Unified2Alert(&tv, &p, data, &pq, NULL);
if(ret == TM_ECODE_FAILED)
}
ret = Unified2Alert(&tv, p, data, &pq, NULL);
if(ret == TM_ECODE_FAILED) {
SCFree(p);
return 0;
}
ret = Unified2AlertThreadDeinit(&tv, data);
if(ret == -1)
if(ret == -1) {
SCFree(p);
return 0;
}
Unified2AlertDeInitCtx(oc);
@ -944,6 +985,7 @@ static int Unified2Test03 (void) {
pkt = PacketDequeue(&pq);
}
SCFree(p);
return 1;
}
@ -969,44 +1011,58 @@ static int Unified2Test04 (void) {
0xea, 0x37, 0x00, 0x17, 0x6d, 0x0b, 0xba, 0xc3,
0x00, 0x00, 0x00, 0x00, 0x60, 0x02, 0x10, 0x20,
0xdd, 0xe1, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
int ret;
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&tv, 0, sizeof(ThreadVars));
memset(&pq, 0, sizeof(PacketQueue));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
p.alerts.cnt++;
p.alerts.alerts[p.alerts.cnt-1].sid = 1;
p.alerts.alerts[p.alerts.cnt-1].gid = 1;
p.alerts.alerts[p.alerts.cnt-1].rev = 1;
p.pktlen = sizeof(raw_ppp);
p->alerts.cnt++;
p->alerts.alerts[p->alerts.cnt-1].sid = 1;
p->alerts.alerts[p->alerts.cnt-1].gid = 1;
p->alerts.alerts[p->alerts.cnt-1].rev = 1;
p->pktlen = sizeof(raw_ppp);
FlowInitConfig(FLOW_QUIET);
DecodePPP(&tv, &dtv, &p, raw_ppp, sizeof(raw_ppp), &pq);
DecodePPP(&tv, &dtv, p, raw_ppp, sizeof(raw_ppp), &pq);
FlowShutdown();
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL)
if (oc == NULL) {
SCFree(p);
return 0;
}
lf = (LogFileCtx *)oc->data;
if(lf == NULL)
if(lf == NULL) {
SCFree(p);
return 0;
}
ret = Unified2AlertThreadInit(&tv, oc, &data);
if(ret == -1)
if(ret == -1) {
SCFree(p);
return 0;
ret = Unified2Alert(&tv, &p, data, &pq, NULL);
if(ret == TM_ECODE_FAILED)
}
ret = Unified2Alert(&tv, p, data, &pq, NULL);
if(ret == TM_ECODE_FAILED) {
SCFree(p);
return 0;
}
ret = Unified2AlertThreadDeinit(&tv, data);
if(ret == -1)
if(ret == -1) {
SCFree(p);
return 0;
}
Unified2AlertDeInitCtx(oc);
SCFree(p);
return 1;
}
@ -1036,46 +1092,60 @@ static int Unified2Test05 (void) {
0x05, 0xb4, 0x04, 0x02, 0x08, 0x0a, 0x00, 0x1c,
0x28, 0x81, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03,
0x03, 0x06};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
int ret;
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&tv, 0, sizeof(ThreadVars));
memset(&pq, 0, sizeof(PacketQueue));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
p.alerts.cnt++;
p.alerts.alerts[p.alerts.cnt-1].sid = 1;
p.alerts.alerts[p.alerts.cnt-1].gid = 1;
p.alerts.alerts[p.alerts.cnt-1].rev = 1;
p.pktlen = sizeof(raw_ipv4_tcp);
p->alerts.cnt++;
p->alerts.alerts[p->alerts.cnt-1].sid = 1;
p->alerts.alerts[p->alerts.cnt-1].gid = 1;
p->alerts.alerts[p->alerts.cnt-1].rev = 1;
p->pktlen = sizeof(raw_ipv4_tcp);
FlowInitConfig(FLOW_QUIET);
DecodeEthernet(&tv, &dtv, &p, raw_ipv4_tcp, sizeof(raw_ipv4_tcp), &pq);
DecodeEthernet(&tv, &dtv, p, raw_ipv4_tcp, sizeof(raw_ipv4_tcp), &pq);
FlowShutdown();
p.action = ACTION_DROP;
p->action = ACTION_DROP;
oc = Unified2AlertInitCtx(NULL);
if (oc == NULL)
if (oc == NULL) {
SCFree(p);
return 0;
}
lf = (LogFileCtx *)oc->data;
if(lf == NULL)
if(lf == NULL) {
SCFree(p);
return 0;
}
ret = Unified2AlertThreadInit(&tv, oc, &data);
if(ret == -1)
if(ret == -1) {
SCFree(p);
return 0;
ret = Unified2Alert(&tv, &p, data, &pq, NULL);
if(ret == TM_ECODE_FAILED)
}
ret = Unified2Alert(&tv, p, data, &pq, NULL);
if(ret == TM_ECODE_FAILED) {
SCFree(p);
return 0;
}
ret = Unified2AlertThreadDeinit(&tv, data);
if(ret == TM_ECODE_FAILED)
if(ret == TM_ECODE_FAILED) {
SCFree(p);
return 0;
}
Unified2AlertDeInitCtx(oc);
SCFree(p);
return 1;
}

@ -1127,7 +1127,9 @@ int SCCudaPBTest01(void)
int result = 0;
SCCudaPBThreadCtx *tctx = NULL;
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
DecodeThreadVars dtv;
ThreadVars tv;
ThreadVars tv_cuda_PB;
@ -1171,13 +1173,14 @@ int SCCudaPBTest01(void)
packets_buffer_len += packets_offset_buffer[(sizeof(strings)/sizeof(char *)) - 1] +
sizeof(SCCudaPBPacketDataForGPUNonPayload) + strlen(strings[(sizeof(strings)/sizeof(char *)) - 1]);
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&tv, 0, sizeof(ThreadVars));
memset(&tv_cuda_PB, 0, sizeof(ThreadVars));
FlowInitConfig(FLOW_QUIET);
DecodeEthernet(&tv, &dtv, &p, raw_eth, sizeof(raw_eth), NULL);
DecodeEthernet(&tv, &dtv, p, raw_eth, sizeof(raw_eth), NULL);
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL) {
@ -1206,81 +1209,81 @@ int SCCudaPBTest01(void)
SCCudaPBThreadInit(&tv_cuda_PB, de_ctx, (void *)&tctx);
SCCudaPBSetBufferPacketThreshhold(sizeof(strings)/sizeof(char *));
p.payload = (uint8_t *)strings[0];
p.payload_len = strlen(strings[0]);
SCCudaPBBatchPackets(NULL, &p, tctx, NULL, NULL);
p->payload = (uint8_t *)strings[0];
p->payload_len = strlen(strings[0]);
SCCudaPBBatchPackets(NULL, p, tctx, NULL, NULL);
dq = &data_queues[tmq_outq->id];
result &= (dq->len == 0);
dq = &data_queues[tmq_inq->id];
result &= (dq->len == 9);
p.payload = (uint8_t *)strings[1];
p.payload_len = strlen(strings[1]);
SCCudaPBBatchPackets(NULL, &p, tctx, NULL, NULL);
p->payload = (uint8_t *)strings[1];
p->payload_len = strlen(strings[1]);
SCCudaPBBatchPackets(NULL, p, tctx, NULL, NULL);
dq = &data_queues[tmq_outq->id];
result &= (dq->len == 0);
dq = &data_queues[tmq_inq->id];
result &= (dq->len == 9);
p.payload = (uint8_t *)strings[2];
p.payload_len = strlen(strings[2]);
SCCudaPBBatchPackets(NULL, &p, tctx, NULL, NULL);
p->payload = (uint8_t *)strings[2];
p->payload_len = strlen(strings[2]);
SCCudaPBBatchPackets(NULL, p, tctx, NULL, NULL);
dq = &data_queues[tmq_outq->id];
result &= (dq->len == 0);
dq = &data_queues[tmq_inq->id];
result &= (dq->len == 9);
p.payload = (uint8_t *)strings[3];
p.payload_len = strlen(strings[3]);
SCCudaPBBatchPackets(NULL, &p, tctx, NULL, NULL);
p->payload = (uint8_t *)strings[3];
p->payload_len = strlen(strings[3]);
SCCudaPBBatchPackets(NULL, p, tctx, NULL, NULL);
dq = &data_queues[tmq_outq->id];
result &= (dq->len == 0);
dq = &data_queues[tmq_inq->id];
result &= (dq->len == 9);
p.payload = (uint8_t *)strings[4];
p.payload_len = strlen(strings[4]);
SCCudaPBBatchPackets(NULL, &p, tctx, NULL, NULL);
p->payload = (uint8_t *)strings[4];
p->payload_len = strlen(strings[4]);
SCCudaPBBatchPackets(NULL, p, tctx, NULL, NULL);
dq = &data_queues[tmq_outq->id];
result &= (dq->len == 0);
dq = &data_queues[tmq_inq->id];
result &= (dq->len == 9);
p.payload = (uint8_t *)strings[5];
p.payload_len = strlen(strings[5]);
SCCudaPBBatchPackets(NULL, &p, tctx, NULL, NULL);
p->payload = (uint8_t *)strings[5];
p->payload_len = strlen(strings[5]);
SCCudaPBBatchPackets(NULL, p, tctx, NULL, NULL);
dq = &data_queues[tmq_outq->id];
result &= (dq->len == 0);
dq = &data_queues[tmq_inq->id];
result &= (dq->len == 9);
p.payload = (uint8_t *)strings[6];
p.payload_len = strlen(strings[6]);
SCCudaPBBatchPackets(NULL, &p, tctx, NULL, NULL);
p->payload = (uint8_t *)strings[6];
p->payload_len = strlen(strings[6]);
SCCudaPBBatchPackets(NULL, p, tctx, NULL, NULL);
dq = &data_queues[tmq_outq->id];
result &= (dq->len == 0);
dq = &data_queues[tmq_inq->id];
result &= (dq->len == 9);
p.payload = (uint8_t *)strings[7];
p.payload_len = strlen(strings[7]);
SCCudaPBBatchPackets(NULL, &p, tctx, NULL, NULL);
p->payload = (uint8_t *)strings[7];
p->payload_len = strlen(strings[7]);
SCCudaPBBatchPackets(NULL, p, tctx, NULL, NULL);
dq = &data_queues[tmq_outq->id];
result &= (dq->len == 0);
dq = &data_queues[tmq_inq->id];
result &= (dq->len == 9);
p.payload = (uint8_t *)strings[8];
p.payload_len = strlen(strings[8]);
SCCudaPBBatchPackets(NULL, &p, tctx, NULL, NULL);
p->payload = (uint8_t *)strings[8];
p->payload_len = strlen(strings[8]);
SCCudaPBBatchPackets(NULL, p, tctx, NULL, NULL);
dq = &data_queues[tmq_outq->id];
result &= (dq->len == 0);
dq = &data_queues[tmq_inq->id];
result &= (dq->len == 9);
p.payload = (uint8_t *)strings[9];
p.payload_len = strlen(strings[9]);
SCCudaPBBatchPackets(NULL, &p, tctx, NULL, NULL);
p->payload = (uint8_t *)strings[9];
p->payload_len = strlen(strings[9]);
SCCudaPBBatchPackets(NULL, p, tctx, NULL, NULL);
dq = &data_queues[tmq_outq->id];
result &= (dq->len == 1);
dq = &data_queues[tmq_inq->id];
@ -1318,6 +1321,7 @@ int SCCudaPBTest01(void)
}
SCCudaPBThreadDeInit(NULL, tctx);
SCFree(p);
return result;
}
@ -1389,7 +1393,9 @@ int SCCudaPBTest02(void)
const char *string = NULL;
SCCudaPBThreadCtx *tctx = NULL;
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
DecodeThreadVars dtv;
ThreadVars tv;
ThreadVars tv_cuda_PB;
@ -1399,13 +1405,14 @@ int SCCudaPBTest02(void)
SCDQDataQueue *dq = NULL;
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&tv, 0, sizeof(ThreadVars));
memset(&tv_cuda_PB, 0, sizeof(ThreadVars));
FlowInitConfig(FLOW_QUIET);
DecodeEthernet(&tv, &dtv, &p, raw_eth, sizeof(raw_eth), NULL);
DecodeEthernet(&tv, &dtv, p, raw_eth, sizeof(raw_eth), NULL);
de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL) {
@ -1434,9 +1441,9 @@ int SCCudaPBTest02(void)
result = 1;
string = "test_one";
p.payload = (uint8_t *)string;
p.payload_len = strlen(string);
SCCudaPBBatchPackets(NULL, &p, tctx, NULL, NULL);
p->payload = (uint8_t *)string;
p->payload_len = strlen(string);
SCCudaPBBatchPackets(NULL, p, tctx, NULL, NULL);
dq = &data_queues[tmq_outq->id];
result &= (dq->len == 0);
dq = &data_queues[tmq_inq->id];
@ -1454,6 +1461,7 @@ int SCCudaPBTest02(void)
}
SCCudaPBThreadDeInit(NULL, tctx);
SCFree(p);
return result;
}

@ -105,16 +105,20 @@ static int DecodeEthernetTest01 (void) {
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd,
0xab, 0xcd };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
DecodeEthernet(&tv, &dtv, &p, raw_eth, sizeof(raw_eth), NULL);
DecodeEthernet(&tv, &dtv, p, raw_eth, sizeof(raw_eth), NULL);
SCFree(p);
return 0;
}
#endif /* UNITTESTS */

@ -257,20 +257,25 @@ void DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u
static int DecodeGREtest01 (void) {
uint8_t raw_gre[] = { 0x00 ,0x6e ,0x62 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
DecodeGRE(&tv, &dtv, &p, raw_gre, sizeof(raw_gre), NULL);
DecodeGRE(&tv, &dtv, p, raw_gre, sizeof(raw_gre), NULL);
if(DECODER_ISSET_EVENT(&p,GRE_PKT_TOO_SMALL)) {
if(DECODER_ISSET_EVENT(p,GRE_PKT_TOO_SMALL)) {
SCFree(p);
return 1;
}
SCFree(p);
return 0;
}
@ -294,20 +299,25 @@ static int DecodeGREtest02 (void) {
0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01,
0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
DecodeGRE(&tv, &dtv, &p, raw_gre, sizeof(raw_gre), NULL);
DecodeGRE(&tv, &dtv, p, raw_gre, sizeof(raw_gre), NULL);
if(DECODER_ISSET_EVENT(&p,GRE_WRONG_VERSION)) {
if(DECODER_ISSET_EVENT(p,GRE_WRONG_VERSION)) {
SCFree(p);
return 1;
}
SCFree(p);
return 0;
}
@ -332,21 +342,26 @@ static int DecodeGREtest03 (void) {
0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00,
0x01, 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
DecodeGRE(&tv, &dtv, &p, raw_gre, sizeof(raw_gre), NULL);
DecodeGRE(&tv, &dtv, p, raw_gre, sizeof(raw_gre), NULL);
if(p.greh == NULL) {
if(p->greh == NULL) {
SCFree(p);
return 0;
}
SCFree(p);
return 1;
}
#endif /* UNITTESTS */

@ -299,7 +299,9 @@ static int DecodeICMPV4test01(void) {
0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
0xab };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
int ret = 0;
@ -307,30 +309,32 @@ static int DecodeICMPV4test01(void) {
memset(&ip4h, 0, sizeof(IPV4Hdr));
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ip4h, 0, sizeof(IPV4Hdr));
memset(&dtv, 0, sizeof(DecodeThreadVars));
FlowInitConfig(FLOW_QUIET);
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.src.addr_data32[0] = 0x01020304;
p.dst.addr_data32[0] = 0x04030201;
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->src.addr_data32[0] = 0x01020304;
p->dst.addr_data32[0] = 0x04030201;
ip4h.ip_src.s_addr = p.src.addr_data32[0];
ip4h.ip_dst.s_addr = p.dst.addr_data32[0];
p.ip4h = &ip4h;
ip4h.ip_src.s_addr = p->src.addr_data32[0];
ip4h.ip_dst.s_addr = p->dst.addr_data32[0];
p->ip4h = &ip4h;
DecodeICMPV4(&tv, &dtv, &p, raw_icmpv4, sizeof(raw_icmpv4), NULL);
DecodeICMPV4(&tv, &dtv, p, raw_icmpv4, sizeof(raw_icmpv4), NULL);
if (NULL!=p.icmpv4h) {
if (p.icmpv4h->type==8 && p.icmpv4h->code==0) {
if (NULL!=p->icmpv4h) {
if (p->icmpv4h->type==8 && p->icmpv4h->code==0) {
ret = 1;
}
}
FlowShutdown();
SCFree(p);
return ret;
}
@ -347,7 +351,9 @@ static int DecodeICMPV4test02(void) {
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
int ret = 0;
@ -355,29 +361,31 @@ static int DecodeICMPV4test02(void) {
memset(&ip4h, 0, sizeof(IPV4Hdr));
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
FlowInitConfig(FLOW_QUIET);
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.src.addr_data32[0] = 0x01020304;
p.dst.addr_data32[0] = 0x04030201;
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->src.addr_data32[0] = 0x01020304;
p->dst.addr_data32[0] = 0x04030201;
ip4h.ip_src.s_addr = p.src.addr_data32[0];
ip4h.ip_dst.s_addr = p.dst.addr_data32[0];
p.ip4h = &ip4h;
ip4h.ip_src.s_addr = p->src.addr_data32[0];
ip4h.ip_dst.s_addr = p->dst.addr_data32[0];
p->ip4h = &ip4h;
DecodeICMPV4(&tv, &dtv, &p, raw_icmpv4, sizeof(raw_icmpv4), NULL);
DecodeICMPV4(&tv, &dtv, p, raw_icmpv4, sizeof(raw_icmpv4), NULL);
if (NULL!=p.icmpv4h) {
if (p.icmpv4h->type==0 && p.icmpv4h->code==0) {
if (NULL!=p->icmpv4h) {
if (p->icmpv4h->type==0 && p->icmpv4h->code==0) {
ret = 1;
}
}
FlowShutdown();
SCFree(p);
return ret;
}
@ -392,7 +400,9 @@ static int DecodeICMPV4test03(void) {
0x01, 0x11, 0xde, 0xfd, 0xc0, 0xa8, 0x01, 0x0d,
0xd1, 0x55, 0xe3, 0x93, 0x8b, 0x12, 0x82, 0xaa,
0x00, 0x28, 0x7c, 0xdd };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
int ret = 0;
@ -400,42 +410,43 @@ static int DecodeICMPV4test03(void) {
memset(&ip4h, 0, sizeof(IPV4Hdr));
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
FlowInitConfig(FLOW_QUIET);
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.src.addr_data32[0] = 0x01020304;
p.dst.addr_data32[0] = 0x04030201;
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->src.addr_data32[0] = 0x01020304;
p->dst.addr_data32[0] = 0x04030201;
ip4h.ip_src.s_addr = p.src.addr_data32[0];
ip4h.ip_dst.s_addr = p.dst.addr_data32[0];
p.ip4h = &ip4h;
ip4h.ip_src.s_addr = p->src.addr_data32[0];
ip4h.ip_dst.s_addr = p->dst.addr_data32[0];
p->ip4h = &ip4h;
DecodeICMPV4(&tv, &dtv, &p, raw_icmpv4, sizeof(raw_icmpv4), NULL);
DecodeICMPV4(&tv, &dtv, p, raw_icmpv4, sizeof(raw_icmpv4), NULL);
if (NULL == p.icmpv4h) {
if (NULL == p->icmpv4h) {
goto end;
}
/* check it's type 11 code 0 */
if (p.icmpv4h->type != 11 || p.icmpv4h->code != 0) {
if (p->icmpv4h->type != 11 || p->icmpv4h->code != 0) {
goto end;
}
/* check it's source port 4747 to port 43650 */
if (p.icmpv4vars.emb_sport != htons(4747) ||
p.icmpv4vars.emb_dport != htons(43650)) {
if (p->icmpv4vars.emb_sport != htons(4747) ||
p->icmpv4vars.emb_dport != htons(43650)) {
goto end;
}
/* check the src,dst IPs contained inside */
char s[16], d[16];
inet_ntop(AF_INET, &(p.icmpv4vars.emb_ip4_src), s, sizeof(s));
inet_ntop(AF_INET, &(p.icmpv4vars.emb_ip4_dst), d, sizeof(d));
inet_ntop(AF_INET, &(p->icmpv4vars.emb_ip4_src), s, sizeof(s));
inet_ntop(AF_INET, &(p->icmpv4vars.emb_ip4_dst), d, sizeof(d));
/* ICMPv4 embedding IPV4 192.168.1.13->209.85.227.147 pass */
if (strcmp(s, "192.168.1.13") == 0 && strcmp(d, "209.85.227.147") == 0) {
@ -444,6 +455,7 @@ static int DecodeICMPV4test03(void) {
end:
FlowShutdown();
SCFree(p);
return ret;
}
@ -460,7 +472,9 @@ static int DecodeICMPV4test04(void) {
0x3e, 0x36, 0x38, 0x7c, 0x00, 0x00, 0x00, 0x00,
0xa0, 0x02, 0x16, 0xd0, 0x72, 0x04, 0x00, 0x00,
0x02, 0x04, 0x05, 0x8a, 0x04, 0x02, 0x08, 0x0a };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
int ret = 0;
@ -468,42 +482,43 @@ static int DecodeICMPV4test04(void) {
memset(&ip4h, 0, sizeof(IPV4Hdr));
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
FlowInitConfig(FLOW_QUIET);
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.src.addr_data32[0] = 0x01020304;
p.dst.addr_data32[0] = 0x04030201;
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->src.addr_data32[0] = 0x01020304;
p->dst.addr_data32[0] = 0x04030201;
ip4h.ip_src.s_addr = p.src.addr_data32[0];
ip4h.ip_dst.s_addr = p.dst.addr_data32[0];
p.ip4h = &ip4h;
ip4h.ip_src.s_addr = p->src.addr_data32[0];
ip4h.ip_dst.s_addr = p->dst.addr_data32[0];
p->ip4h = &ip4h;
DecodeICMPV4(&tv, &dtv, &p, raw_icmpv4, sizeof(raw_icmpv4), NULL);
DecodeICMPV4(&tv, &dtv, p, raw_icmpv4, sizeof(raw_icmpv4), NULL);
if (NULL == p.icmpv4h) {
if (NULL == p->icmpv4h) {
goto end;
}
/* check the type,code pair is correct - type 3, code 10 */
if (p.icmpv4h->type != 3 || p.icmpv4h->code != 10) {
if (p->icmpv4h->type != 3 || p->icmpv4h->code != 10) {
goto end;
}
/* check it's src port 2737 to dst port 12800 */
if (p.icmpv4vars.emb_sport != htons(2737) ||
p.icmpv4vars.emb_dport != htons(12800)) {
if (p->icmpv4vars.emb_sport != htons(2737) ||
p->icmpv4vars.emb_dport != htons(12800)) {
goto end;
}
// check the src,dst IPs contained inside
char s[16], d[16];
inet_ntop(AF_INET, &(p.icmpv4vars.emb_ip4_src), s, sizeof(s));
inet_ntop(AF_INET, &(p.icmpv4vars.emb_ip4_dst), d, sizeof(d));
inet_ntop(AF_INET, &(p->icmpv4vars.emb_ip4_src), s, sizeof(s));
inet_ntop(AF_INET, &(p->icmpv4vars.emb_ip4_dst), d, sizeof(d));
// ICMPv4 embedding IPV4 192.168.1.13->88.96.22.41
if (strcmp(s, "192.168.1.13") == 0 && strcmp(d, "88.96.22.41") == 0) {
@ -512,6 +527,7 @@ static int DecodeICMPV4test04(void) {
end:
FlowShutdown();
SCFree(p);
return ret;
}
@ -561,7 +577,9 @@ static int ICMPV4InvalidType07(void) {
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x38};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
int ret = 0;
@ -569,27 +587,29 @@ static int ICMPV4InvalidType07(void) {
memset(&ip4h, 0, sizeof(IPV4Hdr));
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
FlowInitConfig(FLOW_QUIET);
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.src.addr_data32[0] = 0x01020304;
p.dst.addr_data32[0] = 0x04030201;
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->src.addr_data32[0] = 0x01020304;
p->dst.addr_data32[0] = 0x04030201;
ip4h.ip_src.s_addr = p.src.addr_data32[0];
ip4h.ip_dst.s_addr = p.dst.addr_data32[0];
p.ip4h = &ip4h;
ip4h.ip_src.s_addr = p->src.addr_data32[0];
ip4h.ip_dst.s_addr = p->dst.addr_data32[0];
p->ip4h = &ip4h;
DecodeICMPV4(&tv, &dtv, &p, raw_icmpv4, sizeof(raw_icmpv4), NULL);
DecodeICMPV4(&tv, &dtv, p, raw_icmpv4, sizeof(raw_icmpv4), NULL);
if(DECODER_ISSET_EVENT(&p,ICMPV4_UNKNOWN_TYPE)) {
if(DECODER_ISSET_EVENT(p,ICMPV4_UNKNOWN_TYPE)) {
ret = 1;
}
FlowShutdown();
SCFree(p);
return ret;
}
@ -601,7 +621,9 @@ static int DecodeICMPV4test08(void) {
uint8_t raw_icmpv4[] = {
0x08, 0x00, 0x78, 0x47, 0xfc, 0x55, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
int ret = 0;
@ -609,29 +631,31 @@ static int DecodeICMPV4test08(void) {
memset(&ip4h, 0, sizeof(IPV4Hdr));
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
FlowInitConfig(FLOW_QUIET);
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.src.addr_data32[0] = 0x01020304;
p.dst.addr_data32[0] = 0x04030201;
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->src.addr_data32[0] = 0x01020304;
p->dst.addr_data32[0] = 0x04030201;
ip4h.ip_src.s_addr = p.src.addr_data32[0];
ip4h.ip_dst.s_addr = p.dst.addr_data32[0];
p.ip4h = &ip4h;
ip4h.ip_src.s_addr = p->src.addr_data32[0];
ip4h.ip_dst.s_addr = p->dst.addr_data32[0];
p->ip4h = &ip4h;
DecodeICMPV4(&tv, &dtv, &p, raw_icmpv4, sizeof(raw_icmpv4), NULL);
DecodeICMPV4(&tv, &dtv, p, raw_icmpv4, sizeof(raw_icmpv4), NULL);
if (NULL!=p.icmpv4h) {
if (p.icmpv4h->type==8 && p.icmpv4h->code==0) {
if (NULL!=p->icmpv4h) {
if (p->icmpv4h->type==8 && p->icmpv4h->code==0) {
ret = 1;
}
}
FlowShutdown();
SCFree(p);
return ret;
}
#endif /* UNITTESTS */

@ -352,7 +352,9 @@ static int ICMPV6ParamProbTest01(void)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x08, 0xb5, 0x99, 0xc3, 0xde, 0x40 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV6Hdr ip6h;
ThreadVars tv;
DecodeThreadVars dtv;
@ -362,22 +364,23 @@ static int ICMPV6ParamProbTest01(void)
ipv6dst = (uint32_t*) &raw_ipv6[24];
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip6h, 0, sizeof(IPV6Hdr));
FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, &p, raw_ipv6, sizeof(raw_ipv6), NULL);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p.icmpv6h == NULL) {
if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
retval = 0;
goto end;
}
if (ICMPV6_GET_TYPE(&p) != 4 || ICMPV6_GET_CODE(&p) != 0 ||
ICMPV6_GET_EMB_PROTO(&p) != IPPROTO_ICMPV6) {
if (ICMPV6_GET_TYPE(p) != 4 || ICMPV6_GET_CODE(p) != 0 ||
ICMPV6_GET_EMB_PROTO(p) != IPPROTO_ICMPV6) {
SCLogDebug("ICMPv6 not processed at all");
retval = 0;
goto end;
@ -386,8 +389,8 @@ static int ICMPV6ParamProbTest01(void)
/* Let's check if we retrieved the embedded ipv6 addresses correctly */
uint32_t i=0;
for (i = 0; i < 4; i++) {
if (p.icmpv6vars.emb_ip6_src[i] != ipv6src[i] ||
p.icmpv6vars.emb_ip6_dst[i] != ipv6dst[i]) {
if (p->icmpv6vars.emb_ip6_src[i] != ipv6src[i] ||
p->icmpv6vars.emb_ip6_dst[i] != ipv6dst[i]) {
SCLogDebug("ICMPv6 DecodePartialICMPV6 (Embedded ip6h) didn't set "
"the src and dest ip addresses correctly");
retval = 0;
@ -397,6 +400,7 @@ static int ICMPV6ParamProbTest01(void)
retval = 1;
end:
SCFree(p);
return retval;
}
@ -420,7 +424,9 @@ static int ICMPV6PktTooBigTest01(void)
0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV6Hdr ip6h;
ThreadVars tv;
DecodeThreadVars dtv;
@ -430,22 +436,23 @@ static int ICMPV6PktTooBigTest01(void)
ipv6dst = (uint32_t*) &raw_ipv6[24];
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip6h, 0, sizeof(IPV6Hdr));
FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, &p, raw_ipv6, sizeof(raw_ipv6), NULL);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p.icmpv6h == NULL) {
if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
retval = 0;
goto end;
}
/* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */
if (ICMPV6_GET_TYPE(&p) != 2 || ICMPV6_GET_CODE(&p) != 0 ) {
if (ICMPV6_GET_TYPE(p) != 2 || ICMPV6_GET_CODE(p) != 0 ) {
SCLogDebug("ICMPv6 Not processed at all");
retval = 0;
goto end;
@ -454,8 +461,8 @@ static int ICMPV6PktTooBigTest01(void)
/* Let's check if we retrieved the embedded ipv6 addresses correctly */
uint32_t i=0;
for (i = 0; i < 4; i++) {
if (p.icmpv6vars.emb_ip6_src[i] != ipv6src[i] ||
p.icmpv6vars.emb_ip6_dst[i] != ipv6dst[i]) {
if (p->icmpv6vars.emb_ip6_src[i] != ipv6src[i] ||
p->icmpv6vars.emb_ip6_dst[i] != ipv6dst[i]) {
SCLogDebug("ICMPv6 DecodePartialICMPV6 (Embedded ip6h) didn't set "
"the src and dest ip addresses correctly");
retval = 0;
@ -467,6 +474,7 @@ static int ICMPV6PktTooBigTest01(void)
retval = 1;
end:
SCFree(p);
return retval;
}
@ -490,7 +498,9 @@ static int ICMPV6TimeExceedTest01(void)
0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV6Hdr ip6h;
ThreadVars tv;
DecodeThreadVars dtv;
@ -501,23 +511,24 @@ static int ICMPV6TimeExceedTest01(void)
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip6h, 0, sizeof(IPV6Hdr));
FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, &p, raw_ipv6, sizeof(raw_ipv6), NULL);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p.icmpv6h == NULL) {
if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
retval = 0;
goto end;
}
/* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */
if (ICMPV6_GET_TYPE(&p) != 3 || ICMPV6_GET_CODE(&p) != 0 ||
ICMPV6_GET_EMB_IPV6(&p)==NULL || ICMPV6_GET_EMB_PROTO(&p) != IPPROTO_NONE ) {
if (ICMPV6_GET_TYPE(p) != 3 || ICMPV6_GET_CODE(p) != 0 ||
ICMPV6_GET_EMB_IPV6(p)==NULL || ICMPV6_GET_EMB_PROTO(p) != IPPROTO_NONE ) {
SCLogDebug("ICMPv6 Not processed at all");
retval = 0;
goto end;
@ -526,8 +537,8 @@ static int ICMPV6TimeExceedTest01(void)
/* Let's check if we retrieved the embedded ipv6 addresses correctly */
uint32_t i=0;
for (i = 0; i < 4; i++) {
if (p.icmpv6vars.emb_ip6_src[i] != ipv6src[i] ||
p.icmpv6vars.emb_ip6_dst[i] != ipv6dst[i]) {
if (p->icmpv6vars.emb_ip6_src[i] != ipv6src[i] ||
p->icmpv6vars.emb_ip6_dst[i] != ipv6dst[i]) {
SCLogDebug("ICMPv6 DecodePartialICMPV6 (Embedded ip6h) didn't set "
"the src and dest ip addresses correctly");
retval = 0;
@ -539,6 +550,7 @@ static int ICMPV6TimeExceedTest01(void)
retval = 1;
end:
SCFree(p);
return retval;
}
@ -562,7 +574,9 @@ static int ICMPV6DestUnreachTest01(void)
0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV6Hdr ip6h;
ThreadVars tv;
DecodeThreadVars dtv;
@ -573,23 +587,24 @@ static int ICMPV6DestUnreachTest01(void)
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip6h, 0, sizeof(IPV6Hdr));
FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, &p, raw_ipv6, sizeof(raw_ipv6), NULL);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p.icmpv6h == NULL) {
if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
retval = 0;
goto end;
}
/* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */
if (ICMPV6_GET_TYPE(&p) != 1 || ICMPV6_GET_CODE(&p) != 0 ||
ICMPV6_GET_EMB_IPV6(&p) == NULL || ICMPV6_GET_EMB_PROTO(&p) != IPPROTO_NONE ) {
if (ICMPV6_GET_TYPE(p) != 1 || ICMPV6_GET_CODE(p) != 0 ||
ICMPV6_GET_EMB_IPV6(p) == NULL || ICMPV6_GET_EMB_PROTO(p) != IPPROTO_NONE ) {
SCLogDebug("ICMPv6 Not processed at all");
retval = 0;
goto end;
@ -598,8 +613,8 @@ static int ICMPV6DestUnreachTest01(void)
/* Let's check if we retrieved the embedded ipv6 addresses correctly */
uint32_t i=0;
for (i = 0; i < 4; i++) {
if (p.icmpv6vars.emb_ip6_src[i] != ipv6src[i] ||
p.icmpv6vars.emb_ip6_dst[i] != ipv6dst[i]) {
if (p->icmpv6vars.emb_ip6_src[i] != ipv6src[i] ||
p->icmpv6vars.emb_ip6_dst[i] != ipv6dst[i]) {
SCLogDebug("ICMPv6 DecodePartialICMPV6 (Embedded ip6h) didn't set "
"the src and dest ip addresses correctly");
retval = 0;
@ -609,6 +624,7 @@ static int ICMPV6DestUnreachTest01(void)
retval = 1;
end:
SCFree(p);
return retval;
}
@ -626,30 +642,33 @@ static int ICMPV6EchoReqTest01(void)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV6Hdr ip6h;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip6h, 0, sizeof(IPV6Hdr));
FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, &p, raw_ipv6, sizeof(raw_ipv6), NULL);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p.icmpv6h == NULL) {
if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
retval = 0;
goto end;
}
SCLogDebug("ID: %u seq: %u", ICMPV6_GET_ID(&p), ICMPV6_GET_SEQ(&p));
SCLogDebug("ID: %u seq: %u", ICMPV6_GET_ID(p), ICMPV6_GET_SEQ(p));
if (ICMPV6_GET_TYPE(&p) != 128 || ICMPV6_GET_CODE(&p) != 0 ||
ICMPV6_GET_ID(&p) != 61477 || ICMPV6_GET_SEQ(&p) != 29987) {
if (ICMPV6_GET_TYPE(p) != 128 || ICMPV6_GET_CODE(p) != 0 ||
ICMPV6_GET_ID(p) != 61477 || ICMPV6_GET_SEQ(p) != 29987) {
SCLogDebug("ICMPv6 Echo request decode failed");
retval = 0;
goto end;
@ -657,6 +676,7 @@ static int ICMPV6EchoReqTest01(void)
retval = 1;
end:
SCFree(p);
return retval;
}
@ -675,31 +695,34 @@ static int ICMPV6EchoRepTest01(void)
0x00, 0x00, 0x00, 0x00, 0x01, 0x81, 0x00,
0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV6Hdr ip6h;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip6h, 0, sizeof(IPV6Hdr));
FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, &p, raw_ipv6, sizeof(raw_ipv6), NULL);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p.icmpv6h == NULL) {
if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
retval = 0;
goto end;
}
SCLogDebug("type: %u code %u ID: %u seq: %u", ICMPV6_GET_TYPE(&p),
ICMPV6_GET_CODE(&p),ICMPV6_GET_ID(&p), ICMPV6_GET_SEQ(&p));
SCLogDebug("type: %u code %u ID: %u seq: %u", ICMPV6_GET_TYPE(p),
ICMPV6_GET_CODE(p),ICMPV6_GET_ID(p), ICMPV6_GET_SEQ(p));
if (ICMPV6_GET_TYPE(&p) != 129 || ICMPV6_GET_CODE(&p) != 0 ||
ICMPV6_GET_ID(&p) != 61477 || ICMPV6_GET_SEQ(&p) != 29987) {
if (ICMPV6_GET_TYPE(p) != 129 || ICMPV6_GET_CODE(p) != 0 ||
ICMPV6_GET_ID(p) != 61477 || ICMPV6_GET_SEQ(p) != 29987) {
SCLogDebug("ICMPv6 Echo reply decode failed");
retval = 0;
goto end;
@ -707,6 +730,7 @@ static int ICMPV6EchoRepTest01(void)
retval = 1;
end:
SCFree(p);
return retval;
}
@ -731,33 +755,36 @@ static int ICMPV6ParamProbTest02(void)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x08, 0xb5, 0x99, 0xc3, 0xde, 0x40 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV6Hdr ip6h;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip6h, 0, sizeof(IPV6Hdr));
FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, &p, raw_ipv6, sizeof(raw_ipv6), NULL);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p.icmpv6h == NULL) {
if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
retval = 0;
goto end;
}
if (ICMPV6_GET_TYPE(&p) != 4 || ICMPV6_GET_CODE(&p) != 0) {
if (ICMPV6_GET_TYPE(p) != 4 || ICMPV6_GET_CODE(p) != 0) {
SCLogDebug("ICMPv6 Not processed at all");
retval = 0;
goto end;
}
if (!DECODER_ISSET_EVENT(&p, ICMPV6_IPV6_UNKNOWN_VER)) {
if (!DECODER_ISSET_EVENT(p, ICMPV6_IPV6_UNKNOWN_VER)) {
SCLogDebug("ICMPv6 Error: Unknown embedded ipv6 version event not set");
retval = 0;
goto end;
@ -765,6 +792,7 @@ static int ICMPV6ParamProbTest02(void)
retval = 1;
end:
SCFree(p);
return retval;
}
@ -788,27 +816,30 @@ static int ICMPV6PktTooBigTest02(void)
0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV6Hdr ip6h;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip6h, 0, sizeof(IPV6Hdr));
FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, &p, raw_ipv6, sizeof(raw_ipv6), NULL);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p.icmpv6h == NULL) {
if (p->icmpv6h == NULL) {
SCLogDebug("ICMPv6 Unable to detect icmpv6 layer from ipv6");
retval = 0;
goto end;
}
if (!DECODER_ISSET_EVENT(&p, ICMPV6_UNKNOWN_CODE)) {
if (!DECODER_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
SCLogDebug("ICMPv6 Error: Unknown code event not set");
retval = 0;
goto end;
@ -816,6 +847,7 @@ static int ICMPV6PktTooBigTest02(void)
retval = 1;
end:
SCFree(p);
return retval;
}
@ -836,21 +868,24 @@ static int ICMPV6TimeExceedTest02(void)
/* The icmpv6 header is broken in the checksum (so we dont have a complete header) */
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV6Hdr ip6h;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip6h, 0, sizeof(IPV6Hdr));
FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, &p, raw_ipv6, sizeof(raw_ipv6), NULL);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (!DECODER_ISSET_EVENT(&p, ICMPV6_PKT_TOO_SMALL)) {
if (!DECODER_ISSET_EVENT(p, ICMPV6_PKT_TOO_SMALL)) {
SCLogDebug("ICMPv6 Error: event packet too small not set");
retval = 0;
goto end;
@ -858,6 +893,7 @@ static int ICMPV6TimeExceedTest02(void)
retval = 1;
end:
SCFree(p);
return retval;
}
@ -881,21 +917,24 @@ static int ICMPV6DestUnreachTest02(void)
0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV6Hdr ip6h;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip6h, 0, sizeof(IPV6Hdr));
FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, &p, raw_ipv6, sizeof(raw_ipv6), NULL);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (!DECODER_ISSET_EVENT(&p, ICMPV6_IPV6_TRUNC_PKT)) {
if (!DECODER_ISSET_EVENT(p, ICMPV6_IPV6_TRUNC_PKT)) {
SCLogDebug("ICMPv6 Error: embedded ipv6 truncated packet event not set");
retval = 0;
goto end;
@ -903,6 +942,7 @@ static int ICMPV6DestUnreachTest02(void)
retval = 1;
end:
SCFree(p);
return retval;
}
@ -922,21 +962,24 @@ static int ICMPV6EchoReqTest02(void)
0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01,
0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV6Hdr ip6h;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip6h, 0, sizeof(IPV6Hdr));
FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, &p, raw_ipv6, sizeof(raw_ipv6), NULL);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (!DECODER_ISSET_EVENT(&p, ICMPV6_UNKNOWN_CODE)) {
if (!DECODER_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
SCLogDebug("ICMPv6 Error: Unknown code event not set");
retval = 0;
goto end;
@ -944,6 +987,7 @@ static int ICMPV6EchoReqTest02(void)
retval = 1;
end:
SCFree(p);
return retval;
}
@ -963,21 +1007,24 @@ static int ICMPV6EchoRepTest02(void)
0x00, 0x00, 0x00, 0x00, 0x01, 0x81, 0x01,
0xe5, 0xa5, 0x25, 0xf0, 0x75, 0x23 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV6Hdr ip6h;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip6h, 0, sizeof(IPV6Hdr));
FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, &p, raw_ipv6, sizeof(raw_ipv6), NULL);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (!DECODER_ISSET_EVENT(&p, ICMPV6_UNKNOWN_CODE)) {
if (!DECODER_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)) {
SCLogDebug("ICMPv6 Error: Unknown code event not set");
retval = 0;
goto end;
@ -985,6 +1032,7 @@ static int ICMPV6EchoRepTest02(void)
retval = 1;
end:
SCFree(p);
return retval;
}
@ -1007,32 +1055,36 @@ static int ICMPV6PayloadTest01(void)
0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV6Hdr ip6h;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip6h, 0, sizeof(IPV6Hdr));
FlowInitConfig(FLOW_QUIET);
DecodeIPV6(&tv, &dtv, &p, raw_ipv6, sizeof(raw_ipv6), NULL);
DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6), NULL);
FlowShutdown();
if (p.payload == NULL) {
if (p->payload == NULL) {
printf("payload == NULL, expected non-NULL: ");
goto end;
}
if (p.payload_len != 37) {
printf("payload_len %"PRIu16", expected 37: ", p.payload_len);
if (p->payload_len != 37) {
printf("payload_len %"PRIu16", expected 37: ", p->payload_len);
goto end;
}
retval = 1;
end:
SCFree(p);
return retval;
}

@ -624,18 +624,22 @@ void DecodeIPV4OptionsPrint(Packet *p) {
/** \test IPV4 with no options. */
int DecodeIPV4OptionsNONETest01(void) {
uint8_t raw_opts[] = { };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
uint8_t *data = (uint8_t *)&p;
uint8_t *data = (uint8_t *)p;
uint16_t i;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
if (rc != 0) {
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -643,11 +647,13 @@ int DecodeIPV4OptionsNONETest01(void) {
if (*data) {
/* Should not have modified packet data */
//printf("Data modified at offset %" PRIu16 "\n", i);
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
}
SCFree(p);
return 1;
}
@ -656,18 +662,22 @@ int DecodeIPV4OptionsEOLTest01(void) {
uint8_t raw_opts[] = {
IPV4_OPT_EOL, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
uint8_t *data = (uint8_t *)&p;
uint8_t *data = (uint8_t *)p;
uint16_t i;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
if (rc != 0) {
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -675,11 +685,13 @@ int DecodeIPV4OptionsEOLTest01(void) {
if (*data) {
/* Should not have modified packet data */
//printf("Data modified at offset %" PRIu16 "\n", i);
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
}
SCFree(p);
return 1;
}
@ -688,18 +700,22 @@ int DecodeIPV4OptionsNOPTest01(void) {
uint8_t raw_opts[] = {
IPV4_OPT_NOP, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
uint8_t *data = (uint8_t *)&p;
uint8_t *data = (uint8_t *)p;
uint16_t i;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
if (rc != 0) {
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -707,11 +723,13 @@ int DecodeIPV4OptionsNOPTest01(void) {
if (*data) {
/* Should not have modified packet data */
//printf("Data modified at offset %" PRIu16 "\n", i);
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
}
SCFree(p);
return 1;
}
@ -724,25 +742,30 @@ int DecodeIPV4OptionsRRTest01(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rr, (uintmax_t)&p.IPV4_OPTS[0]);
if ( (rc == 0)
&& (p.IPV4_OPTS_CNT == 1)
&& (p.IPV4_OPTS[0].type == IPV4_OPT_RR)
&& (p.IPV4_OPTS[0].len == 0x27)
&& (p.ip4vars.o_rr == &p.IPV4_OPTS[0]))
&& (p->IPV4_OPTS_CNT == 1)
&& (p->IPV4_OPTS[0].type == IPV4_OPT_RR)
&& (p->IPV4_OPTS[0].len == 0x27)
&& (p->ip4vars.o_rr == &p->IPV4_OPTS[0]))
{
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -755,20 +778,25 @@ int DecodeIPV4OptionsRRTest02(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rr, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -781,20 +809,25 @@ int DecodeIPV4OptionsRRTest03(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rr, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -807,20 +840,25 @@ int DecodeIPV4OptionsRRTest04(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rr, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -829,25 +867,30 @@ int DecodeIPV4OptionsQSTest01(void) {
uint8_t raw_opts[] = {
IPV4_OPT_QS, 0x08, 0x0d, 0x00, 0xbe, 0xef, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",qs=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_qs, (uintmax_t)&p.IPV4_OPTS[0]);
if ( (rc == 0)
&& (p.IPV4_OPTS_CNT == 1)
&& (p.IPV4_OPTS[0].type == IPV4_OPT_QS)
&& (p.IPV4_OPTS[0].len == 0x08)
&& (p.ip4vars.o_qs == &p.IPV4_OPTS[0]))
&& (p->IPV4_OPTS_CNT == 1)
&& (p->IPV4_OPTS[0].type == IPV4_OPT_QS)
&& (p->IPV4_OPTS[0].len == 0x08)
&& (p->ip4vars.o_qs == &p->IPV4_OPTS[0]))
{
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -856,20 +899,25 @@ int DecodeIPV4OptionsQSTest02(void) {
uint8_t raw_opts[] = {
IPV4_OPT_QS, 0x07, 0x0d, 0x00, 0xbe, 0xef, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",qs=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_qs, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -882,25 +930,30 @@ int DecodeIPV4OptionsTSTest01(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ts=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ts, (uintmax_t)&p.IPV4_OPTS[0]);
if ( (rc == 0)
&& (p.IPV4_OPTS_CNT == 1)
&& (p.IPV4_OPTS[0].type == IPV4_OPT_TS)
&& (p.IPV4_OPTS[0].len == 0x24)
&& (p.ip4vars.o_ts == &p.IPV4_OPTS[0]))
&& (p->IPV4_OPTS_CNT == 1)
&& (p->IPV4_OPTS[0].type == IPV4_OPT_TS)
&& (p->IPV4_OPTS[0].len == 0x24)
&& (p->ip4vars.o_ts == &p->IPV4_OPTS[0]))
{
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -913,20 +966,25 @@ int DecodeIPV4OptionsTSTest02(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ts=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ts, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -939,20 +997,25 @@ int DecodeIPV4OptionsTSTest03(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ts=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ts, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -965,20 +1028,25 @@ int DecodeIPV4OptionsTSTest04(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ts=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ts, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -988,25 +1056,30 @@ int DecodeIPV4OptionsSECTest01(void) {
IPV4_OPT_SEC, 0x0b, 0xf1, 0x35, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",sec=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_sec, (uintmax_t)&p.IPV4_OPTS[0]);
if ( (rc == 0)
&& (p.IPV4_OPTS_CNT == 1)
&& (p.IPV4_OPTS[0].type == IPV4_OPT_SEC)
&& (p.IPV4_OPTS[0].len == 0x0b)
&& (p.ip4vars.o_sec == &p.IPV4_OPTS[0]))
&& (p->IPV4_OPTS_CNT == 1)
&& (p->IPV4_OPTS[0].type == IPV4_OPT_SEC)
&& (p->IPV4_OPTS[0].len == 0x0b)
&& (p->ip4vars.o_sec == &p->IPV4_OPTS[0]))
{
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -1016,20 +1089,25 @@ int DecodeIPV4OptionsSECTest02(void) {
IPV4_OPT_SEC, 0x0a, 0xf1, 0x35, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",sec=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_sec, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -1042,25 +1120,30 @@ int DecodeIPV4OptionsLSRRTest01(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",lsrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_lsrr, (uintmax_t)&p.IPV4_OPTS[0]);
if ( (rc == 0)
&& (p.IPV4_OPTS_CNT == 1)
&& (p.IPV4_OPTS[0].type == IPV4_OPT_LSRR)
&& (p.IPV4_OPTS[0].len == 0x27)
&& (p.ip4vars.o_lsrr == &p.IPV4_OPTS[0]))
&& (p->IPV4_OPTS_CNT == 1)
&& (p->IPV4_OPTS[0].type == IPV4_OPT_LSRR)
&& (p->IPV4_OPTS[0].len == 0x27)
&& (p->ip4vars.o_lsrr == &p->IPV4_OPTS[0]))
{
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -1073,20 +1156,25 @@ int DecodeIPV4OptionsLSRRTest02(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",lsrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_lsrr, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -1099,20 +1187,25 @@ int DecodeIPV4OptionsLSRRTest03(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",lsrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_lsrr, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -1125,20 +1218,25 @@ int DecodeIPV4OptionsLSRRTest04(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",lsrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_lsrr, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -1149,25 +1247,30 @@ int DecodeIPV4OptionsCIPSOTest01(void) {
0x00, 0x03, 0x00, 0xef, 0x00, 0xef, 0x00, 0x06,
0x00, 0x04, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_cipso, (uintmax_t)&p.IPV4_OPTS[0]);
if ( (rc == 0)
&& (p.IPV4_OPTS_CNT == 1)
&& (p.IPV4_OPTS[0].type == IPV4_OPT_CIPSO)
&& (p.IPV4_OPTS[0].len == 0x18)
&& (p.ip4vars.o_cipso == &p.IPV4_OPTS[0]))
&& (p->IPV4_OPTS_CNT == 1)
&& (p->IPV4_OPTS[0].type == IPV4_OPT_CIPSO)
&& (p->IPV4_OPTS[0].len == 0x18)
&& (p->ip4vars.o_cipso == &p->IPV4_OPTS[0]))
{
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -1176,25 +1279,30 @@ int DecodeIPV4OptionsSIDTest01(void) {
uint8_t raw_opts[] = {
IPV4_OPT_SID, 0x04, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",sid=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_sid, (uintmax_t)&p.IPV4_OPTS[0]);
if ( (rc == 0)
&& (p.IPV4_OPTS_CNT == 1)
&& (p.IPV4_OPTS[0].type == IPV4_OPT_SID)
&& (p.IPV4_OPTS[0].len == 0x04)
&& (p.ip4vars.o_sid == &p.IPV4_OPTS[0]))
&& (p->IPV4_OPTS_CNT == 1)
&& (p->IPV4_OPTS[0].type == IPV4_OPT_SID)
&& (p->IPV4_OPTS[0].len == 0x04)
&& (p->ip4vars.o_sid == &p->IPV4_OPTS[0]))
{
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -1203,20 +1311,25 @@ int DecodeIPV4OptionsSIDTest02(void) {
uint8_t raw_opts[] = {
IPV4_OPT_SID, 0x05, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",sid=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_sid, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -1229,25 +1342,30 @@ int DecodeIPV4OptionsSSRRTest01(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ssrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ssrr, (uintmax_t)&p.IPV4_OPTS[0]);
if ( (rc == 0)
&& (p.IPV4_OPTS_CNT == 1)
&& (p.IPV4_OPTS[0].type == IPV4_OPT_SSRR)
&& (p.IPV4_OPTS[0].len == 0x27)
&& (p.ip4vars.o_ssrr == &p.IPV4_OPTS[0]))
&& (p->IPV4_OPTS_CNT == 1)
&& (p->IPV4_OPTS[0].type == IPV4_OPT_SSRR)
&& (p->IPV4_OPTS[0].len == 0x27)
&& (p->ip4vars.o_ssrr == &p->IPV4_OPTS[0]))
{
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -1260,20 +1378,25 @@ int DecodeIPV4OptionsSSRRTest02(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ssrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ssrr, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -1286,20 +1409,25 @@ int DecodeIPV4OptionsSSRRTest03(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ssrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ssrr, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -1312,20 +1440,25 @@ int DecodeIPV4OptionsSSRRTest04(void) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ssrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ssrr, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -1334,25 +1467,30 @@ int DecodeIPV4OptionsRTRALTTest01(void) {
uint8_t raw_opts[] = {
IPV4_OPT_RTRALT, 0x04, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rtralt=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rtralt, (uintmax_t)&p.IPV4_OPTS[0]);
if ( (rc == 0)
&& (p.IPV4_OPTS_CNT == 1)
&& (p.IPV4_OPTS[0].type == IPV4_OPT_RTRALT)
&& (p.IPV4_OPTS[0].len == 0x04)
&& (p.ip4vars.o_rtralt == &p.IPV4_OPTS[0]))
&& (p->IPV4_OPTS_CNT == 1)
&& (p->IPV4_OPTS[0].type == IPV4_OPT_RTRALT)
&& (p->IPV4_OPTS[0].len == 0x04)
&& (p->ip4vars.o_rtralt == &p->IPV4_OPTS[0]))
{
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}
@ -1361,20 +1499,25 @@ int DecodeIPV4OptionsRTRALTTest02(void) {
uint8_t raw_opts[] = {
IPV4_OPT_RTRALT, 0x05, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int rc;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
rc = DecodeIPV4Options(&tv, p, raw_opts, sizeof(raw_opts));
//printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rtralt=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rtralt, (uintmax_t)&p.IPV4_OPTS[0]);
if (rc != 0) {
SCFree(p);
return 1;
}
DecodeIPV4OptionsPrint(&p);
DecodeIPV4OptionsPrint(p);
SCFree(p);
return 0;
}

@ -131,22 +131,27 @@ void DecodePPP(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u
*/
static int DecodePPPtest01 (void) {
uint8_t raw_ppp[] = { 0xff, 0x03, 0x00, 0x21, 0x45, 0xc0, 0x00 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
DecodePPP(&tv, &dtv, &p, raw_ppp, sizeof(raw_ppp), NULL);
DecodePPP(&tv, &dtv, p, raw_ppp, sizeof(raw_ppp), NULL);
/* Function my returns here with expected value */
if(DECODER_ISSET_EVENT(&p,PPPIPV4_PKT_TOO_SMALL)) {
if(DECODER_ISSET_EVENT(p,PPPIPV4_PKT_TOO_SMALL)) {
SCFree(p);
return 1;
}
SCFree(p);
return 0;
}
@ -160,22 +165,27 @@ static int DecodePPPtest02 (void) {
0x0d, 0x01, 0xbf, 0x01, 0x0d, 0x03, 0xea, 0x37, 0x00,
0x17, 0x6d, 0x0b, 0xba, 0xc3, 0x00, 0x00, 0x00, 0x00,
0x60, 0x02, 0x10, 0x20, 0xdd, 0xe1, 0x00, 0x00 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
DecodePPP(&tv, &dtv, &p, raw_ppp, sizeof(raw_ppp), NULL);
DecodePPP(&tv, &dtv, p, raw_ppp, sizeof(raw_ppp), NULL);
/* Function must returns here */
if(DECODER_ISSET_EVENT(&p,PPP_WRONG_TYPE)) {
if(DECODER_ISSET_EVENT(p,PPP_WRONG_TYPE)) {
SCFree(p);
return 1;
}
SCFree(p);
return 0;
}
@ -191,41 +201,50 @@ static int DecodePPPtest03 (void) {
0x0d, 0x01, 0xbf, 0x01, 0x0d, 0x03, 0xea, 0x37, 0x00,
0x17, 0x6d, 0x0b, 0xba, 0xc3, 0x00, 0x00, 0x00, 0x00,
0x60, 0x02, 0x10, 0x20, 0xdd, 0xe1, 0x00, 0x00 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
FlowInitConfig(FLOW_QUIET);
DecodePPP(&tv, &dtv, &p, raw_ppp, sizeof(raw_ppp), NULL);
DecodePPP(&tv, &dtv, p, raw_ppp, sizeof(raw_ppp), NULL);
FlowShutdown();
if(p.ppph == NULL) {
if(p->ppph == NULL) {
SCFree(p);
return 0;
}
if(DECODER_ISSET_EVENT(&p,PPP_PKT_TOO_SMALL)) {
if(DECODER_ISSET_EVENT(p,PPP_PKT_TOO_SMALL)) {
SCFree(p);
return 0;
}
if(DECODER_ISSET_EVENT(&p,PPPIPV4_PKT_TOO_SMALL)) {
if(DECODER_ISSET_EVENT(p,PPPIPV4_PKT_TOO_SMALL)) {
SCFree(p);
return 0;
}
if(DECODER_ISSET_EVENT(&p,PPP_WRONG_TYPE)) {
if(DECODER_ISSET_EVENT(p,PPP_WRONG_TYPE)) {
SCFree(p);
return 0;
}
if (!(DECODER_ISSET_EVENT(&p,IPV4_TRUNC_PKT))) {
if (!(DECODER_ISSET_EVENT(p,IPV4_TRUNC_PKT))) {
SCFree(p);
return 0;
}
/* Function must return here */
SCFree(p);
return 1;
}
@ -241,30 +260,36 @@ static int DecodePPPtest04 (void) {
0x0d, 0x01, 0xbf, 0x01, 0x0d, 0x03, 0xea, 0x37, 0x00,
0x17, 0x6d, 0x0b, 0xba, 0xc3, 0x00, 0x00, 0x00, 0x00,
0x60, 0x02, 0x10, 0x20, 0xdd, 0xe1, 0x00, 0x00 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
FlowInitConfig(FLOW_QUIET);
DecodePPP(&tv, &dtv, &p, raw_ppp, sizeof(raw_ppp), NULL);
DecodePPP(&tv, &dtv, p, raw_ppp, sizeof(raw_ppp), NULL);
FlowShutdown();
if(p.ppph == NULL) {
if(p->ppph == NULL) {
SCFree(p);
return 0;
}
if (!(DECODER_ISSET_EVENT(&p,IPV4_TRUNC_PKT))) {
if (!(DECODER_ISSET_EVENT(p,IPV4_TRUNC_PKT))) {
SCFree(p);
return 0;
}
/* Function must returns here */
SCFree(p);
return 1;
}
#endif /* UNITTESTS */

@ -219,20 +219,25 @@ void DecodePPPOESession(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_
static int DecodePPPOEtest01 (void) {
uint8_t raw_pppoe[] = { 0x11, 0x00, 0x00, 0x00, 0x00 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
DecodePPPOESession(&tv, &dtv, &p, raw_pppoe, sizeof(raw_pppoe), NULL);
DecodePPPOESession(&tv, &dtv, p, raw_pppoe, sizeof(raw_pppoe), NULL);
if (DECODER_ISSET_EVENT(&p,PPPOE_PKT_TOO_SMALL)) {
if (DECODER_ISSET_EVENT(p,PPPOE_PKT_TOO_SMALL)) {
SCFree(p);
return 1;
}
SCFree(p);
return 0;
}
@ -253,32 +258,36 @@ static int DecodePPPOEtest02 (void) {
0x55, 0x56, 0x57, 0x41, 0x42, 0x43, 0x44, 0x45,
0x46, 0x47, 0x48, 0x49 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
int ret = 0;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
FlowInitConfig(FLOW_QUIET);
DecodePPPOESession(&tv, &dtv, &p, raw_pppoe, sizeof(raw_pppoe), NULL);
DecodePPPOESession(&tv, &dtv, p, raw_pppoe, sizeof(raw_pppoe), NULL);
if(DECODER_ISSET_EVENT(&p,PPPOE_PKT_TOO_SMALL)) {
if(DECODER_ISSET_EVENT(p,PPPOE_PKT_TOO_SMALL)) {
goto end;
}
// and we insist that the invalid ICMP encapsulated (type 0xab, code 0xcd) is flagged
if(! DECODER_ISSET_EVENT(&p,ICMPV4_UNKNOWN_TYPE)) {
if(! DECODER_ISSET_EVENT(p,ICMPV4_UNKNOWN_TYPE)) {
goto end;
}
ret = 1;
end:
FlowShutdown();
SCFree(p);
return ret;
}
@ -298,18 +307,24 @@ static int DecodePPPOEtest03 (void) {
0x65, 0x73, 0x68, 0x6f, 0x6f, 0x74
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
DecodePPPOEDiscovery(&tv, &dtv, &p, raw_pppoe, sizeof(raw_pppoe), NULL);
if (p.pppoedh == NULL)
return 0;
DecodePPPOEDiscovery(&tv, &dtv, p, raw_pppoe, sizeof(raw_pppoe), NULL);
if (p->pppoedh == NULL) {
SCFree(p);
return 0;
}
SCFree(p);
return 1;
}
@ -325,20 +340,25 @@ static int DecodePPPOEtest04 (void) {
0x00, 0x00
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
DecodePPPOEDiscovery(&tv, &dtv, &p, raw_pppoe, sizeof(raw_pppoe), NULL);
DecodePPPOEDiscovery(&tv, &dtv, p, raw_pppoe, sizeof(raw_pppoe), NULL);
if(DECODER_ISSET_EVENT(&p,PPPOE_WRONG_CODE)) {
if(DECODER_ISSET_EVENT(p,PPPOE_WRONG_CODE)) {
SCFree(p);
return 1;
}
SCFree(p);
return 0;
}
@ -356,20 +376,25 @@ static int DecodePPPOEtest05 (void) {
0x20, 0x2d, 0x20, 0x65, 0x73, 0x68, 0x73, 0x68
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
DecodePPPOEDiscovery(&tv, &dtv, &p, raw_pppoe, sizeof(raw_pppoe), NULL);
DecodePPPOEDiscovery(&tv, &dtv, p, raw_pppoe, sizeof(raw_pppoe), NULL);
if(DECODER_ISSET_EVENT(&p,PPPOE_MALFORMED_TAGS)) {
if(DECODER_ISSET_EVENT(p,PPPOE_MALFORMED_TAGS)) {
SCFree(p);
return 1;
}
SCFree(p);
return 0;
}

@ -76,27 +76,34 @@ static int DecodeRawTest01 (void) {
0x29, 0x9c, 0x00, 0x00, 0x02, 0x04, 0x05, 0x8c,
0x04, 0x02, 0x08, 0x0a, 0x00, 0xdd, 0x1a, 0x39,
0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x02 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
if (PacketCopyData(&p, raw_ip, sizeof(raw_ip)) == -1)
return 1;
if (PacketCopyData(p, raw_ip, sizeof(raw_ip)) == -1) {
SCFree(p);
return 1;
}
FlowInitConfig(FLOW_QUIET);
DecodeRaw(&tv, &dtv, &p, raw_ip, p.pktlen, NULL);
if (p.ip6h == NULL) {
DecodeRaw(&tv, &dtv, p, raw_ip, p->pktlen, NULL);
if (p->ip6h == NULL) {
printf("expected a valid ipv6 header but it was NULL: ");
FlowShutdown();
SCFree(p);
return 1;
}
FlowShutdown();
SCFree(p);
return 0;
}
@ -115,26 +122,33 @@ static int DecodeRawTest02 (void) {
0x70, 0x02, 0x40, 0x00, 0xb8, 0xc8, 0x00, 0x00,
0x02, 0x04, 0x05, 0xb4, 0x01, 0x01, 0x04, 0x02 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
if (PacketCopyData(&p, raw_ip, sizeof(raw_ip)) == -1)
return 1;
if (PacketCopyData(p, raw_ip, sizeof(raw_ip)) == -1) {
SCFree(p);
return 1;
}
FlowInitConfig(FLOW_QUIET);
DecodeRaw(&tv, &dtv, &p, raw_ip, p.pktlen, NULL);
DecodeRaw(&tv, &dtv, p, raw_ip, p->pktlen, NULL);
FlowShutdown();
if (p.ip4h == NULL) {
if (p->ip4h == NULL) {
printf("expected a valid ipv4 header but it was NULL: ");
SCFree(p);
return 1;
}
SCFree(p);
return 0;
}
/** DecodeRawtest03
@ -154,27 +168,34 @@ static int DecodeRawTest03 (void) {
0x34, 0x40, 0x67, 0x31, 0x3b, 0x63, 0x61, 0x74,
0x20, 0x6b, 0x65, 0x79, 0x3b };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
if (PacketCopyData(&p, raw_ip, sizeof(raw_ip)) == -1)
return 1;
if (PacketCopyData(p, raw_ip, sizeof(raw_ip)) == -1) {
SCFree(p);
return 1;
}
FlowInitConfig(FLOW_QUIET);
DecodeRaw(&tv, &dtv, &p, raw_ip, p.pktlen, NULL);
if (DECODER_ISSET_EVENT(&p,IPRAW_INVALID_IPV)) {
DecodeRaw(&tv, &dtv, p, raw_ip, p->pktlen, NULL);
if (DECODER_ISSET_EVENT(p,IPRAW_INVALID_IPV)) {
FlowShutdown();
SCFree(p);
return 0;
} else {
printf("expected IPRAW_INVALID_IPV to be set but it wasn't: ");
}
FlowShutdown();
SCFree(p);
return 1;
}

@ -279,31 +279,34 @@ static int TCPGetWscaleTest01(void)
0x8a, 0xaf, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4,
0x04, 0x02, 0x08, 0x0a, 0x00, 0x62, 0x88, 0x28,
0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x02};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV4Hdr ip4h;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip4h, 0, sizeof(IPV4Hdr));
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.ip4h = &ip4h;
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->ip4h = &ip4h;
FlowInitConfig(FLOW_QUIET);
DecodeTCP(&tv, &dtv, &p, raw_tcp, sizeof(raw_tcp), NULL);
DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp), NULL);
FlowShutdown();
if (p.tcph == NULL) {
if (p->tcph == NULL) {
printf("tcp packet decode failed: ");
goto end;
}
uint8_t wscale = TCP_GET_WSCALE(&p);
uint8_t wscale = TCP_GET_WSCALE(p);
if (wscale != 2) {
printf("wscale %"PRIu8", expected 2: ", wscale);
goto end;
@ -311,6 +314,7 @@ static int TCPGetWscaleTest01(void)
retval = 1;
end:
SCFree(p);
return retval;
}
@ -323,30 +327,33 @@ static int TCPGetWscaleTest02(void)
0x8a, 0xaf, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4,
0x04, 0x02, 0x08, 0x0a, 0x00, 0x62, 0x88, 0x28,
0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x0f};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV4Hdr ip4h;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip4h, 0, sizeof(IPV4Hdr));
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.ip4h = &ip4h;
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->ip4h = &ip4h;
FlowInitConfig(FLOW_QUIET);
DecodeTCP(&tv, &dtv, &p, raw_tcp, sizeof(raw_tcp), NULL);
DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp), NULL);
FlowShutdown();
if (p.tcph == NULL) {
if (p->tcph == NULL) {
printf("tcp packet decode failed: ");
goto end;
}
uint8_t wscale = TCP_GET_WSCALE(&p);
uint8_t wscale = TCP_GET_WSCALE(p);
if (wscale != 0) {
printf("wscale %"PRIu8", expected 0: ", wscale);
goto end;
@ -354,6 +361,7 @@ static int TCPGetWscaleTest02(void)
retval = 1;
end:
SCFree(p);
return retval;
}
@ -365,30 +373,33 @@ static int TCPGetWscaleTest03(void)
0xdd, 0xa3, 0x6f, 0xf8, 0x80, 0x10, 0x05, 0xb4,
0x7c, 0x70, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a,
0x00, 0x62, 0x88, 0x9e, 0x00, 0x00, 0x00, 0x00};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV4Hdr ip4h;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip4h, 0, sizeof(IPV4Hdr));
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.ip4h = &ip4h;
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->ip4h = &ip4h;
FlowInitConfig(FLOW_QUIET);
DecodeTCP(&tv, &dtv, &p, raw_tcp, sizeof(raw_tcp), NULL);
DecodeTCP(&tv, &dtv, p, raw_tcp, sizeof(raw_tcp), NULL);
FlowShutdown();
if (p.tcph == NULL) {
if (p->tcph == NULL) {
printf("tcp packet decode failed: ");
goto end;
}
uint8_t wscale = TCP_GET_WSCALE(&p);
uint8_t wscale = TCP_GET_WSCALE(p);
if (wscale != 0) {
printf("wscale %"PRIu8", expected 0: ", wscale);
goto end;
@ -396,6 +407,7 @@ static int TCPGetWscaleTest03(void)
retval = 1;
end:
SCFree(p);
return retval;
}
#endif /* UNITTESTS */

@ -104,20 +104,25 @@ void DecodeVLAN(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
*/
static int DecodeVLANtest01 (void) {
uint8_t raw_vlan[] = { 0x00, 0x20, 0x08 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
DecodeVLAN(&tv, &dtv, &p, raw_vlan, sizeof(raw_vlan), NULL);
DecodeVLAN(&tv, &dtv, p, raw_vlan, sizeof(raw_vlan), NULL);
if(DECODER_ISSET_EVENT(&p,VLAN_HEADER_TOO_SMALL)) {
if(DECODER_ISSET_EVENT(p,VLAN_HEADER_TOO_SMALL)) {
SCFree(p);
return 1;
}
SCFree(p);
return 0;
}
@ -136,21 +141,26 @@ static int DecodeVLANtest02 (void) {
0x4d, 0x3d, 0x5a, 0x61, 0x80, 0x10, 0x6b, 0x50,
0x3c, 0x4c, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a,
0x00, 0x04, 0xf0, 0xc8, 0x01, 0x99, 0xa3, 0xf3};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
DecodeVLAN(&tv, &dtv, &p, raw_vlan, sizeof(raw_vlan), NULL);
DecodeVLAN(&tv, &dtv, p, raw_vlan, sizeof(raw_vlan), NULL);
if(DECODER_ISSET_EVENT(&p,VLAN_UNKNOWN_TYPE)) {
if(DECODER_ISSET_EVENT(p,VLAN_UNKNOWN_TYPE)) {
SCFree(p);
return 1;
}
SCFree(p);
return 0;
}
@ -169,32 +179,39 @@ static int DecodeVLANtest03 (void) {
0x4d, 0x3d, 0x5a, 0x61, 0x80, 0x10, 0x6b, 0x50,
0x3c, 0x4c, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a,
0x00, 0x04, 0xf0, 0xc8, 0x01, 0x99, 0xa3, 0xf3};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
FlowInitConfig(FLOW_QUIET);
DecodeVLAN(&tv, &dtv, &p, raw_vlan, sizeof(raw_vlan), NULL);
DecodeVLAN(&tv, &dtv, p, raw_vlan, sizeof(raw_vlan), NULL);
FlowShutdown();
if(p.vlanh == NULL) {
if(p->vlanh == NULL) {
SCFree(p);
return 0;
}
if(DECODER_ISSET_EVENT(&p,VLAN_HEADER_TOO_SMALL)) {
if(DECODER_ISSET_EVENT(p,VLAN_HEADER_TOO_SMALL)) {
SCFree(p);
return 0;
}
if(DECODER_ISSET_EVENT(&p,VLAN_UNKNOWN_TYPE)) {
if(DECODER_ISSET_EVENT(p,VLAN_UNKNOWN_TYPE)) {
SCFree(p);
return 0;
}
SCFree(p);
return 1;
}
#endif /* UNITTESTS */

@ -681,18 +681,21 @@ int DetectContentLongPatternMatchTest(uint8_t *raw_eth_pkt, uint16_t pktsize, ch
{
int result = 0;
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
DecodeThreadVars dtv;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&th_v, 0, sizeof(th_v));
FlowInitConfig(FLOW_QUIET);
DecodeEthernet(&th_v, &dtv, &p, raw_eth_pkt, pktsize, NULL);
DecodeEthernet(&th_v, &dtv, p, raw_eth_pkt, pktsize, NULL);
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL) {
@ -721,8 +724,8 @@ int DetectContentLongPatternMatchTest(uint8_t *raw_eth_pkt, uint16_t pktsize, ch
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
if (PacketAlertCheck(&p, sid) != 1) {
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
if (PacketAlertCheck(p, sid) != 1) {
goto end;
}
@ -738,6 +741,7 @@ end:
}
FlowShutdown();
SCFree(p);
return result;
}

@ -286,7 +286,9 @@ int DecodeEventTestParse05 (void) {
* \test DecodeEventTestParse06 is a test for match function with valid decode-event value
*/
int DecodeEventTestParse06 (void) {
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int ret = 0;
DetectDecodeEventData *de = NULL;
@ -294,9 +296,10 @@ int DecodeEventTestParse06 (void) {
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
DECODER_SET_EVENT(&p,PPP_PKT_TOO_SMALL);
DECODER_SET_EVENT(p,PPP_PKT_TOO_SMALL);
de = DetectDecodeEventParse("ppp.pkt_too_small");
if (de == NULL)
@ -311,14 +314,17 @@ int DecodeEventTestParse06 (void) {
sm->type = DETECT_DECODE_EVENT;
sm->ctx = (void *)de;
ret = DetectDecodeEventMatch(&tv,NULL,&p,NULL,sm);
ret = DetectDecodeEventMatch(&tv,NULL,p,NULL,sm);
if(ret)
if(ret) {
SCFree(p);
return 1;
}
error:
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
}
#endif /* UNITTESTS */

@ -694,7 +694,9 @@ int DetectDsizeIcmpv6Test01 (void) {
0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
IPV6Hdr ip6h;
ThreadVars tv;
DecodeThreadVars dtv;
@ -703,17 +705,18 @@ int DetectDsizeIcmpv6Test01 (void) {
DetectEngineThreadCtx *det_ctx = NULL;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ip6h, 0, sizeof(IPV6Hdr));
memset(&th_v, 0, sizeof(ThreadVars));
FlowInitConfig(FLOW_QUIET);
p.src.family = AF_INET6;
p.dst.family = AF_INET6;
p.ip6h = &ip6h;
p->src.family = AF_INET6;
p->dst.family = AF_INET6;
p->ip6h = &ip6h;
DecodeIPV6(&tv, &dtv, &p, raw_icmpv6, sizeof(raw_icmpv6), NULL);
DecodeIPV6(&tv, &dtv, p, raw_icmpv6, sizeof(raw_icmpv6), NULL);
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL) {
@ -737,11 +740,11 @@ int DetectDsizeIcmpv6Test01 (void) {
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) {
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)) {
} else if (PacketAlertCheck(p, 2)) {
printf("sid 2 alerted, but should not have: ");
goto cleanup;
}
@ -757,6 +760,7 @@ cleanup:
FlowShutdown();
end:
SCFree(p);
return result;
}

@ -534,7 +534,9 @@ static int FlagsTestParse02 (void) {
* \retval 0 on failure
*/
static int FlagsTestParse03 (void) {
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int ret = 0;
DetectFlagsData *de = NULL;
@ -543,13 +545,14 @@ static int FlagsTestParse03 (void) {
TCPHdr tcph;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ipv4h, 0, sizeof(IPV4Hdr));
memset(&tcph, 0, sizeof(TCPHdr));
p.ip4h = &ipv4h;
p.tcph = &tcph;
p.tcph->th_flags = TH_ACK|TH_PUSH|TH_SYN|TH_RST;
p->ip4h = &ipv4h;
p->tcph = &tcph;
p->tcph->th_flags = TH_ACK|TH_PUSH|TH_SYN|TH_RST;
de = DetectFlagsParse("AP+");
@ -563,17 +566,19 @@ static int FlagsTestParse03 (void) {
sm->type = DETECT_FLAGS;
sm->ctx = (void *)de;
ret = DetectFlagsMatch(&tv,NULL,&p,NULL,sm);
ret = DetectFlagsMatch(&tv,NULL,p,NULL,sm);
if(ret) {
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 1;
}
error:
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
}
@ -584,7 +589,9 @@ error:
* \retval 0 on failure
*/
static int FlagsTestParse04 (void) {
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int ret = 0;
DetectFlagsData *de = NULL;
@ -593,13 +600,14 @@ static int FlagsTestParse04 (void) {
TCPHdr tcph;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ipv4h, 0, sizeof(IPV4Hdr));
memset(&tcph, 0, sizeof(TCPHdr));
p.ip4h = &ipv4h;
p.tcph = &tcph;
p.tcph->th_flags = TH_SYN;
p->ip4h = &ipv4h;
p->tcph = &tcph;
p->tcph->th_flags = TH_SYN;
de = DetectFlagsParse("A");
@ -613,17 +621,19 @@ static int FlagsTestParse04 (void) {
sm->type = DETECT_FLAGS;
sm->ctx = (void *)de;
ret = DetectFlagsMatch(&tv,NULL,&p,NULL,sm);
ret = DetectFlagsMatch(&tv,NULL,p,NULL,sm);
if(ret) {
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 1;
}
error:
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
}
@ -634,7 +644,9 @@ error:
* \retval 0 on failure
*/
static int FlagsTestParse05 (void) {
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int ret = 0;
DetectFlagsData *de = NULL;
@ -643,13 +655,14 @@ static int FlagsTestParse05 (void) {
TCPHdr tcph;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ipv4h, 0, sizeof(IPV4Hdr));
memset(&tcph, 0, sizeof(TCPHdr));
p.ip4h = &ipv4h;
p.tcph = &tcph;
p.tcph->th_flags = TH_ACK|TH_PUSH|TH_SYN|TH_RST;
p->ip4h = &ipv4h;
p->tcph = &tcph;
p->tcph->th_flags = TH_ACK|TH_PUSH|TH_SYN|TH_RST;
de = DetectFlagsParse("+AP,SR");
@ -663,17 +676,19 @@ static int FlagsTestParse05 (void) {
sm->type = DETECT_FLAGS;
sm->ctx = (void *)de;
ret = DetectFlagsMatch(&tv,NULL,&p,NULL,sm);
ret = DetectFlagsMatch(&tv,NULL,p,NULL,sm);
if(ret) {
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 1;
}
error:
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
}
@ -684,7 +699,9 @@ error:
* \retval 0 on failure
*/
static int FlagsTestParse06 (void) {
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int ret = 0;
DetectFlagsData *de = NULL;
@ -693,13 +710,14 @@ static int FlagsTestParse06 (void) {
TCPHdr tcph;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ipv4h, 0, sizeof(IPV4Hdr));
memset(&tcph, 0, sizeof(TCPHdr));
p.ip4h = &ipv4h;
p.tcph = &tcph;
p.tcph->th_flags = TH_ACK|TH_PUSH|TH_SYN|TH_RST;
p->ip4h = &ipv4h;
p->tcph = &tcph;
p->tcph->th_flags = TH_ACK|TH_PUSH|TH_SYN|TH_RST;
de = DetectFlagsParse("+AP,UR");
@ -713,17 +731,19 @@ static int FlagsTestParse06 (void) {
sm->type = DETECT_FLAGS;
sm->ctx = (void *)de;
ret = DetectFlagsMatch(&tv,NULL,&p,NULL,sm);
ret = DetectFlagsMatch(&tv,NULL,p,NULL,sm);
if(ret) {
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 1;
}
error:
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
}
@ -734,7 +754,9 @@ error:
* \retval 0 on failure
*/
static int FlagsTestParse07 (void) {
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int ret = 0;
DetectFlagsData *de = NULL;
@ -743,13 +765,14 @@ static int FlagsTestParse07 (void) {
TCPHdr tcph;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ipv4h, 0, sizeof(IPV4Hdr));
memset(&tcph, 0, sizeof(TCPHdr));
p.ip4h = &ipv4h;
p.tcph = &tcph;
p.tcph->th_flags = TH_SYN|TH_RST;
p->ip4h = &ipv4h;
p->tcph = &tcph;
p->tcph->th_flags = TH_SYN|TH_RST;
de = DetectFlagsParse("*AP");
@ -763,17 +786,19 @@ static int FlagsTestParse07 (void) {
sm->type = DETECT_FLAGS;
sm->ctx = (void *)de;
ret = DetectFlagsMatch(&tv,NULL,&p,NULL,sm);
ret = DetectFlagsMatch(&tv,NULL,p,NULL,sm);
if(ret) {
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 1;
}
error:
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
}
@ -784,7 +809,9 @@ error:
* \retval 0 on failure
*/
static int FlagsTestParse08 (void) {
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int ret = 0;
DetectFlagsData *de = NULL;
@ -793,13 +820,14 @@ static int FlagsTestParse08 (void) {
TCPHdr tcph;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ipv4h, 0, sizeof(IPV4Hdr));
memset(&tcph, 0, sizeof(TCPHdr));
p.ip4h = &ipv4h;
p.tcph = &tcph;
p.tcph->th_flags = TH_SYN|TH_RST;
p->ip4h = &ipv4h;
p->tcph = &tcph;
p->tcph->th_flags = TH_SYN|TH_RST;
de = DetectFlagsParse("*SA");
@ -813,17 +841,19 @@ static int FlagsTestParse08 (void) {
sm->type = DETECT_FLAGS;
sm->ctx = (void *)de;
ret = DetectFlagsMatch(&tv,NULL,&p,NULL,sm);
ret = DetectFlagsMatch(&tv,NULL,p,NULL,sm);
if(ret) {
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 1;
}
error:
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
}
@ -834,7 +864,9 @@ error:
* \retval 0 on failure
*/
static int FlagsTestParse09 (void) {
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int ret = 0;
DetectFlagsData *de = NULL;
@ -843,13 +875,14 @@ static int FlagsTestParse09 (void) {
TCPHdr tcph;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ipv4h, 0, sizeof(IPV4Hdr));
memset(&tcph, 0, sizeof(TCPHdr));
p.ip4h = &ipv4h;
p.tcph = &tcph;
p.tcph->th_flags = TH_SYN|TH_RST;
p->ip4h = &ipv4h;
p->tcph = &tcph;
p->tcph->th_flags = TH_SYN|TH_RST;
de = DetectFlagsParse("!PA");
@ -863,17 +896,19 @@ static int FlagsTestParse09 (void) {
sm->type = DETECT_FLAGS;
sm->ctx = (void *)de;
ret = DetectFlagsMatch(&tv,NULL,&p,NULL,sm);
ret = DetectFlagsMatch(&tv,NULL,p,NULL,sm);
if(ret) {
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 1;
}
error:
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
}
@ -884,7 +919,9 @@ error:
* \retval 0 on failure
*/
static int FlagsTestParse10 (void) {
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int ret = 0;
DetectFlagsData *de = NULL;
@ -893,13 +930,14 @@ static int FlagsTestParse10 (void) {
TCPHdr tcph;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ipv4h, 0, sizeof(IPV4Hdr));
memset(&tcph, 0, sizeof(TCPHdr));
p.ip4h = &ipv4h;
p.tcph = &tcph;
p.tcph->th_flags = TH_SYN|TH_RST;
p->ip4h = &ipv4h;
p->tcph = &tcph;
p->tcph->th_flags = TH_SYN|TH_RST;
de = DetectFlagsParse("!AP");
@ -913,17 +951,19 @@ static int FlagsTestParse10 (void) {
sm->type = DETECT_FLAGS;
sm->ctx = (void *)de;
ret = DetectFlagsMatch(&tv,NULL,&p,NULL,sm);
ret = DetectFlagsMatch(&tv,NULL,p,NULL,sm);
if(ret) {
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 1;
}
error:
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
}
@ -934,7 +974,9 @@ error:
* \retval 0 on failure
*/
static int FlagsTestParse11 (void) {
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int ret = 0;
DetectFlagsData *de = NULL;
@ -943,13 +985,14 @@ static int FlagsTestParse11 (void) {
TCPHdr tcph;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ipv4h, 0, sizeof(IPV4Hdr));
memset(&tcph, 0, sizeof(TCPHdr));
p.ip4h = &ipv4h;
p.tcph = &tcph;
p.tcph->th_flags = TH_SYN|TH_RST|TH_URG;
p->ip4h = &ipv4h;
p->tcph = &tcph;
p->tcph->th_flags = TH_SYN|TH_RST|TH_URG;
de = DetectFlagsParse("*AP,SR");
@ -963,17 +1006,19 @@ static int FlagsTestParse11 (void) {
sm->type = DETECT_FLAGS;
sm->ctx = (void *)de;
ret = DetectFlagsMatch(&tv,NULL,&p,NULL,sm);
ret = DetectFlagsMatch(&tv,NULL,p,NULL,sm);
if(ret) {
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 1;
}
error:
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
}
@ -984,7 +1029,9 @@ error:
* \retval 0 on failure
*/
static int FlagsTestParse12 (void) {
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int ret = 0;
DetectFlagsData *de = NULL;
@ -993,13 +1040,14 @@ static int FlagsTestParse12 (void) {
TCPHdr tcph;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ipv4h, 0, sizeof(IPV4Hdr));
memset(&tcph, 0, sizeof(TCPHdr));
p.ip4h = &ipv4h;
p.tcph = &tcph;
p.tcph->th_flags = TH_SYN;
p->ip4h = &ipv4h;
p->tcph = &tcph;
p->tcph->th_flags = TH_SYN;
de = DetectFlagsParse("0");
@ -1015,17 +1063,19 @@ static int FlagsTestParse12 (void) {
sm->type = DETECT_FLAGS;
sm->ctx = (void *)de;
ret = DetectFlagsMatch(&tv,NULL,&p,NULL,sm);
ret = DetectFlagsMatch(&tv,NULL,p,NULL,sm);
if(ret) {
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 1;
}
error:
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
}

@ -289,7 +289,9 @@ static int FlowBitsTestSig01(void) {
"Host: one.example.org\r\n"
"\r\n";
uint16_t buflen = strlen((char *)buf);
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
Signature *s = NULL;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
@ -297,12 +299,13 @@ static int FlowBitsTestSig01(void) {
int result = 0;
memset(&th_v, 0, sizeof(th_v));
memset(&p, 0, sizeof(p));
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.payload = buf;
p.payload_len = buflen;
p.proto = IPPROTO_TCP;
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->payload = buf;
p->payload_len = buflen;
p->proto = IPPROTO_TCP;
de_ctx = DetectEngineCtxInit();
@ -321,7 +324,7 @@ static int FlowBitsTestSig01(void) {
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
result = 1;
@ -344,6 +347,7 @@ end:
DetectEngineCtxFree(de_ctx);
}
SCFree(p);
return result;
}
@ -360,7 +364,9 @@ static int FlowBitsTestSig02(void) {
"Host: one.example.org\r\n"
"\r\n";
uint16_t buflen = strlen((char *)buf);
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
Signature *s = NULL;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
@ -369,12 +375,13 @@ static int FlowBitsTestSig02(void) {
int error_count = 0;
memset(&th_v, 0, sizeof(th_v));
memset(&p, 0, sizeof(p));
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.payload = buf;
p.payload_len = buflen;
p.proto = IPPROTO_TCP;
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->payload = buf;
p->payload_len = buflen;
p->proto = IPPROTO_TCP;
de_ctx = DetectEngineCtxInit();
@ -420,21 +427,21 @@ static int FlowBitsTestSig02(void) {
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
if (PacketAlertCheck(&p, 1)) {
if (PacketAlertCheck(p, 1)) {
goto cleanup;
}
if (PacketAlertCheck(&p, 2)) {
if (PacketAlertCheck(p, 2)) {
goto cleanup;
}
if (PacketAlertCheck(&p, 3)) {
if (PacketAlertCheck(p, 3)) {
goto cleanup;
}
if (PacketAlertCheck(&p, 4)) {
if (PacketAlertCheck(p, 4)) {
goto cleanup;
}
if (PacketAlertCheck(&p, 5)) {
if (PacketAlertCheck(p, 5)) {
goto cleanup;
}
@ -462,6 +469,7 @@ end:
DetectEngineCtxFree(de_ctx);
}
SCFree(p);
return result;
}
@ -478,7 +486,9 @@ static int FlowBitsTestSig03(void) {
"Host: one.example.org\r\n"
"\r\n";
uint16_t buflen = strlen((char *)buf);
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
Signature *s = NULL;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
@ -486,12 +496,13 @@ static int FlowBitsTestSig03(void) {
int result = 0;
memset(&th_v, 0, sizeof(th_v));
memset(&p, 0, sizeof(p));
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.payload = buf;
p.payload_len = buflen;
p.proto = IPPROTO_TCP;
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->payload = buf;
p->payload_len = buflen;
p->proto = IPPROTO_TCP;
de_ctx = DetectEngineCtxInit();
@ -510,7 +521,7 @@ static int FlowBitsTestSig03(void) {
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
result = 1;
@ -536,6 +547,7 @@ end:
}
SCFree(p);
return result;
}
@ -552,7 +564,9 @@ static int FlowBitsTestSig04(void) {
"Host: one.example.org\r\n"
"\r\n";
uint16_t buflen = strlen((char *)buf);
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
Signature *s = NULL;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
@ -561,12 +575,13 @@ static int FlowBitsTestSig04(void) {
int idx = 0;
memset(&th_v, 0, sizeof(th_v));
memset(&p, 0, sizeof(p));
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.payload = buf;
p.payload_len = buflen;
p.proto = IPPROTO_TCP;
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->payload = buf;
p->payload_len = buflen;
p->proto = IPPROTO_TCP;
de_ctx = DetectEngineCtxInit();
@ -587,7 +602,7 @@ static int FlowBitsTestSig04(void) {
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
result = 1;
@ -596,6 +611,7 @@ static int FlowBitsTestSig04(void) {
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
SCFree(p);
return result;
end:
@ -613,6 +629,7 @@ end:
DetectEngineCtxFree(de_ctx);
}
SCFree(p);
return result;
}
@ -629,7 +646,9 @@ static int FlowBitsTestSig05(void) {
"Host: one.example.org\r\n"
"\r\n";
uint16_t buflen = strlen((char *)buf);
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
Signature *s = NULL;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
@ -637,12 +656,13 @@ static int FlowBitsTestSig05(void) {
int result = 0;
memset(&th_v, 0, sizeof(th_v));
memset(&p, 0, sizeof(p));
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.payload = buf;
p.payload_len = buflen;
p.proto = IPPROTO_TCP;
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->payload = buf;
p->payload_len = buflen;
p->proto = IPPROTO_TCP;
de_ctx = DetectEngineCtxInit();
@ -661,7 +681,7 @@ static int FlowBitsTestSig05(void) {
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
result = 1;
@ -671,6 +691,7 @@ static int FlowBitsTestSig05(void) {
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
DetectEngineCtxFree(de_ctx);
SCFree(p);
return result;
end:
@ -687,6 +708,7 @@ end:
DetectEngineCtxFree(de_ctx);
}
SCFree(p);
return result;
}
@ -703,7 +725,9 @@ static int FlowBitsTestSig06(void) {
"Host: one.example.org\r\n"
"\r\n";
uint16_t buflen = strlen((char *)buf);
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
Signature *s = NULL;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
@ -713,21 +737,22 @@ static int FlowBitsTestSig06(void) {
int result = 0;
int idx = 0;
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&th_v, 0, sizeof(th_v));
memset(&f, 0, sizeof(Flow));
memset(&flowvar, 0, sizeof(GenericVar));
FLOW_INITIALIZE(&f);
p.flow = &f;
p.flow->flowvar = &flowvar;
p->flow = &f;
p->flow->flowvar = &flowvar;
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.payload = buf;
p.payload_len = buflen;
p.proto = IPPROTO_TCP;
p.flags |= PKT_HAS_FLOW;
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->payload = buf;
p->payload_len = buflen;
p->proto = IPPROTO_TCP;
p->flags |= PKT_HAS_FLOW;
de_ctx = DetectEngineCtxInit();
@ -746,11 +771,11 @@ static int FlowBitsTestSig06(void) {
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
idx = VariableNameGetIdx("myflow",DETECT_FLOWBITS);
gv = p.flow->flowvar;
gv = p->flow->flowvar;
for ( ; gv != NULL; gv = gv->next) {
if (gv->type == DETECT_FLOWBITS && gv->idx == idx) {
@ -767,6 +792,7 @@ static int FlowBitsTestSig06(void) {
if(gv) GenericVarFree(gv);
FLOW_DESTROY(&f);
SCFree(p);
return result;
end:
@ -785,6 +811,7 @@ end:
if(gv) GenericVarFree(gv);
FLOW_DESTROY(&f);
SCFree(p);
return result;
}
@ -801,7 +828,9 @@ static int FlowBitsTestSig07(void) {
"Host: one.example.org\r\n"
"\r\n";
uint16_t buflen = strlen((char *)buf);
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
Signature *s = NULL;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
@ -811,20 +840,21 @@ static int FlowBitsTestSig07(void) {
int result = 0;
int idx = 0;
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&th_v, 0, sizeof(th_v));
memset(&f, 0, sizeof(Flow));
memset(&flowvar, 0, sizeof(GenericVar));
FLOW_INITIALIZE(&f);
p.flow = &f;
p.flow->flowvar = &flowvar;
p->flow = &f;
p->flow->flowvar = &flowvar;
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.payload = buf;
p.payload_len = buflen;
p.proto = IPPROTO_TCP;
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->payload = buf;
p->payload_len = buflen;
p->proto = IPPROTO_TCP;
de_ctx = DetectEngineCtxInit();
@ -847,11 +877,11 @@ static int FlowBitsTestSig07(void) {
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
idx = VariableNameGetIdx("myflow",DETECT_FLOWBITS);
gv = p.flow->flowvar;
gv = p->flow->flowvar;
for ( ; gv != NULL; gv = gv->next) {
if (gv->type == DETECT_FLOWBITS && gv->idx == idx) {
@ -868,6 +898,7 @@ static int FlowBitsTestSig07(void) {
if(gv) GenericVarFree(gv);
FLOW_DESTROY(&f);
SCFree(p);
return result;
end:
@ -887,6 +918,7 @@ end:
if(gv) GenericVarFree(gv);
FLOW_DESTROY(&f);
SCFree(p);
return result;
}
@ -903,7 +935,9 @@ static int FlowBitsTestSig08(void) {
"Host: one.example.org\r\n"
"\r\n";
uint16_t buflen = strlen((char *)buf);
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
Signature *s = NULL;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
@ -913,20 +947,21 @@ static int FlowBitsTestSig08(void) {
int result = 0;
int idx = 0;
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&th_v, 0, sizeof(th_v));
memset(&f, 0, sizeof(Flow));
memset(&flowvar, 0, sizeof(GenericVar));
FLOW_INITIALIZE(&f);
p.flow = &f;
p.flow->flowvar = &flowvar;
p->flow = &f;
p->flow->flowvar = &flowvar;
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.payload = buf;
p.payload_len = buflen;
p.proto = IPPROTO_TCP;
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->payload = buf;
p->payload_len = buflen;
p->proto = IPPROTO_TCP;
de_ctx = DetectEngineCtxInit();
@ -951,11 +986,11 @@ static int FlowBitsTestSig08(void) {
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
idx = VariableNameGetIdx("myflow",DETECT_FLOWBITS);
gv = p.flow->flowvar;
gv = p->flow->flowvar;
for ( ; gv != NULL; gv = gv->next) {
if (gv->type == DETECT_FLOWBITS && gv->idx == idx) {
@ -972,6 +1007,7 @@ static int FlowBitsTestSig08(void) {
if(gv) GenericVarFree(gv);
FLOW_DESTROY(&f);
SCFree(p);
return result;
end:
@ -991,6 +1027,7 @@ end:
if(gv) GenericVarFree(gv);
FLOW_DESTROY(&f);
SCFree(p);
return result;
}
#endif /* UNITTESTS */

@ -1368,7 +1368,9 @@ int DetectFlowintTestPacket01Real()
sizeof(pkt11)
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
DecodeThreadVars dtv;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
@ -1412,38 +1414,39 @@ int DetectFlowintTestPacket01Real()
/* Decode the packets, and test the matches*/
for (i = 0;i < 11;i++) {
memset(&p, 0, SIZE_OF_PACKET);
DecodeEthernet(&th_v, &dtv, &p, pkts[i], pktssizes[i], NULL);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
DecodeEthernet(&th_v, &dtv, p, pkts[i], pktssizes[i], NULL);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
switch(i) {
case 3:
if (PacketAlertCheck(&p, 101) == 0) {
if (PacketAlertCheck(p, 101) == 0) {
SCLogDebug("Not declared/initialized!");
result = 0;
}
break;
case 5:
if (PacketAlertCheck(&p, 102) == 0) {
if (PacketAlertCheck(p, 102) == 0) {
SCLogDebug("Not incremented!");
result = 0;
}
if (PacketAlertCheck(&p, 103) == 0) {
if (PacketAlertCheck(p, 103) == 0) {
SCLogDebug("myvar is not 3 or bad cmp!!");
result = 0;
}
break;
case 10:
if (PacketAlertCheck(&p, 105) == 0) {
if (PacketAlertCheck(p, 105) == 0) {
SCLogDebug("Not declared/initialized/or well incremented the"
" second var!");
result = 0;
}
break;
}
SCLogDebug("Raw Packet %d has %u alerts ", i, p.alerts.cnt);
SCLogDebug("Raw Packet %d has %u alerts ", i, p->alerts.cnt);
}
SigGroupCleanup(de_ctx);
@ -1453,6 +1456,7 @@ int DetectFlowintTestPacket01Real()
DetectEngineCtxFree(de_ctx);
FlowShutdown();
SCFree(p);
return result;
end:
@ -1466,6 +1470,7 @@ end:
DetectEngineCtxFree(de_ctx);
FlowShutdown();
SCFree(p);
return result;
}
@ -1703,7 +1708,9 @@ int DetectFlowintTestPacket02Real()
sizeof(pkt11)
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
DecodeThreadVars dtv;
ThreadVars th_v;
@ -1749,38 +1756,39 @@ int DetectFlowintTestPacket02Real()
/* Decode the packets, and test the matches*/
for (i = 0;i < 11;i++) {
memset(&p, 0, SIZE_OF_PACKET);
DecodeEthernet(&th_v, &dtv, &p, pkts[i], pktssizes[i], NULL);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
DecodeEthernet(&th_v, &dtv, p, pkts[i], pktssizes[i], NULL);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
switch(i) {
case 3:
if (PacketAlertCheck(&p, 101) == 0) {
if (PacketAlertCheck(p, 101) == 0) {
SCLogDebug("Not declared/initialized!");
result = 0;
}
break;
case 5:
if (PacketAlertCheck(&p, 102) == 0) {
if (PacketAlertCheck(p, 102) == 0) {
SCLogDebug("Not incremented!");
result = 0;
}
if (PacketAlertCheck(&p, 103) == 0) {
if (PacketAlertCheck(p, 103) == 0) {
SCLogDebug("myvar is not 3 or bad cmp!!");
result = 0;
}
break;
case 10:
if (PacketAlertCheck(&p, 105) == 0) {
if (PacketAlertCheck(p, 105) == 0) {
SCLogDebug("Not declared/initialized/or well incremented the"
" second var!");
result = 0;
}
break;
}
SCLogDebug("Raw Packet %d has %u alerts ", i, p.alerts.cnt);
SCLogDebug("Raw Packet %d has %u alerts ", i, p->alerts.cnt);
}
SigGroupCleanup(de_ctx);
@ -1791,6 +1799,7 @@ int DetectFlowintTestPacket02Real()
DetectEngineCtxFree(de_ctx);
FlowShutdown();
SCFree(p);
return result;
end:
@ -1805,6 +1814,7 @@ end:
DetectEngineCtxFree(de_ctx);
FlowShutdown();
SCFree(p);
return result;
}
@ -2042,7 +2052,9 @@ int DetectFlowintTestPacket03Real()
sizeof(pkt11)
};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
DecodeThreadVars dtv;
ThreadVars th_v;
@ -2082,35 +2094,36 @@ int DetectFlowintTestPacket03Real()
/* Decode the packets, and test the matches*/
for (i = 0;i < 11;i++) {
memset(&p, 0, SIZE_OF_PACKET);
DecodeEthernet(&th_v, &dtv, &p, pkts[i], pktssizes[i], NULL);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
DecodeEthernet(&th_v, &dtv, p, pkts[i], pktssizes[i], NULL);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
switch(i) {
case 3:
if (PacketAlertCheck(&p, 101) == 0) {
if (PacketAlertCheck(p, 101) == 0) {
SCLogDebug("Not declared/initialized but match!");
result = 0;
}
if (PacketAlertCheck(&p, 103) != 0) {
if (PacketAlertCheck(p, 103) != 0) {
SCLogDebug(" var lala is never set, it should NOT match!!");
result = 0;
}
break;
case 5:
if (PacketAlertCheck(&p, 102) == 0) {
if (PacketAlertCheck(p, 102) == 0) {
SCLogDebug("Not incremented!");
result = 0;
}
if (PacketAlertCheck(&p, 103) != 0) {
if (PacketAlertCheck(p, 103) != 0) {
SCLogDebug(" var lala is never set, it should NOT match!!");
result = 0;
}
break;
}
SCLogDebug("Raw Packet %d has %u alerts ", i, p.alerts.cnt);
SCLogDebug("Raw Packet %d has %u alerts ", i, p->alerts.cnt);
}
SigGroupCleanup(de_ctx);
@ -2121,6 +2134,7 @@ int DetectFlowintTestPacket03Real()
DetectEngineCtxFree(de_ctx);
FlowShutdown();
SCFree(p);
return result;
end:
@ -2135,6 +2149,7 @@ end:
DetectEngineCtxFree(de_ctx);
FlowShutdown();
SCFree(p);
return result;
}

@ -393,7 +393,9 @@ static int FragBitsTestParse03 (void) {
0x0b ,0xc0 ,0x9f ,0x00 ,0x01 ,0x00 ,0x01 ,0x00,
0x00 ,0x0e ,0x10 ,0x00 ,0x04 ,0x81 ,0x6f ,0x0b,
0x51};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
IPV4Hdr ipv4h;
@ -402,16 +404,17 @@ static int FragBitsTestParse03 (void) {
SigMatch *sm = NULL;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ipv4h, 0, sizeof(IPV4Hdr));
AlpProtoFinalize2Thread(&dtv.udp_dp_ctx);
p.ip4h = &ipv4h;
p->ip4h = &ipv4h;
FlowInitConfig(FLOW_QUIET);
DecodeEthernet(&tv, &dtv, &p, raw_eth, sizeof(raw_eth), NULL);
DecodeEthernet(&tv, &dtv, p, raw_eth, sizeof(raw_eth), NULL);
de = DetectFragBitsParse("D");
@ -425,11 +428,12 @@ static int FragBitsTestParse03 (void) {
sm->type = DETECT_FRAGBITS;
sm->ctx = (void *)de;
ret = DetectFragBitsMatch(&tv,NULL,&p,NULL,sm);
ret = DetectFragBitsMatch(&tv,NULL,p,NULL,sm);
if(ret) {
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 1;
}
@ -437,6 +441,7 @@ error:
FlowShutdown();
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
}
@ -485,7 +490,9 @@ static int FragBitsTestParse04 (void) {
0x0b ,0xc0 ,0x9f ,0x00 ,0x01 ,0x00 ,0x01 ,0x00,
0x00 ,0x0e ,0x10 ,0x00 ,0x04 ,0x81 ,0x6f ,0x0b,
0x51};
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
DecodeThreadVars dtv;
IPV4Hdr ipv4h;
@ -494,16 +501,17 @@ static int FragBitsTestParse04 (void) {
SigMatch *sm = NULL;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&ipv4h, 0, sizeof(IPV4Hdr));
AlpProtoFinalize2Thread(&dtv.udp_dp_ctx);
p.ip4h = &ipv4h;
p->ip4h = &ipv4h;
FlowInitConfig(FLOW_QUIET);
DecodeEthernet(&tv, &dtv, &p, raw_eth, sizeof(raw_eth), NULL);
DecodeEthernet(&tv, &dtv, p, raw_eth, sizeof(raw_eth), NULL);
FlowShutdown();
@ -519,17 +527,19 @@ static int FragBitsTestParse04 (void) {
sm->type = DETECT_FRAGBITS;
sm->ctx = (void *)de;
ret = DetectFragBitsMatch(&tv,NULL,&p,NULL,sm);
ret = DetectFragBitsMatch(&tv,NULL,p,NULL,sm);
if(ret) {
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 1;
}
error:
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
}
#endif /* UNITTESTS */

@ -293,29 +293,32 @@ int DetectFragOffsetParseTest03 (void) {
*/
int DetectFragOffsetMatchTest01 (void) {
int result = 0;
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
Signature *s = NULL;
DecodeThreadVars dtv;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
IPV4Hdr ip4h;
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ip4h, 0, sizeof(IPV4Hdr));
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&th_v, 0, sizeof(ThreadVars));
FlowInitConfig(FLOW_QUIET);
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.src.addr_data32[0] = 0x01020304;
p.dst.addr_data32[0] = 0x04030201;
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->src.addr_data32[0] = 0x01020304;
p->dst.addr_data32[0] = 0x04030201;
ip4h.ip_src.s_addr = p.src.addr_data32[0];
ip4h.ip_dst.s_addr = p.dst.addr_data32[0];
ip4h.ip_src.s_addr = p->src.addr_data32[0];
ip4h.ip_dst.s_addr = p->dst.addr_data32[0];
ip4h.ip_off = 0x2222;
p.ip4h = &ip4h;
p->ip4h = &ip4h;
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL) {
@ -337,11 +340,11 @@ int DetectFragOffsetMatchTest01 (void) {
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) {
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)) {
} else if (PacketAlertCheck(p, 2)) {
printf("sid 2 alerted, but should not have: ");
goto cleanup;
}
@ -357,6 +360,7 @@ cleanup:
FlowShutdown();
end:
SCFree(p);
return result;
}

@ -449,31 +449,34 @@ static int DetectFtpbounceTestALMatch03(void) {
TcpSession ssn;
Flow f;
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
Signature *s = NULL;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
memset(&th_v, 0, sizeof(th_v));
memset(&p, 0, sizeof(p));
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&f, 0, sizeof(f));
memset(&ssn, 0, sizeof(ssn));
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.src.addr_data32[0] = 0x04030201;
p.payload = NULL;
p.payload_len = 0;
p.proto = IPPROTO_TCP;
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->src.addr_data32[0] = 0x04030201;
p->payload = NULL;
p->payload_len = 0;
p->proto = IPPROTO_TCP;
FLOW_INITIALIZE(&f);
f.src.address.address_un_data32[0]=0x04030201;
f.protoctx =(void *)&ssn;
p.flow = &f;
p.flowflags |= FLOW_PKT_TOSERVER;
p.flowflags |= FLOW_PKT_ESTABLISHED;
p.flags |= PKT_HAS_FLOW;
p->flow = &f;
p->flowflags |= FLOW_PKT_TOSERVER;
p->flowflags |= FLOW_PKT_ESTABLISHED;
p->flags |= PKT_HAS_FLOW;
f.alproto = ALPROTO_FTP;
StreamTcpInitConfig(TRUE);
@ -537,10 +540,10 @@ static int DetectFtpbounceTestALMatch03(void) {
}
/* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
/* It should not match */
if (!(PacketAlertCheck(&p, 1))) {
if (!(PacketAlertCheck(p, 1))) {
result = 1;
} else {
SCLogDebug("It should not match here!");
@ -556,6 +559,7 @@ end:
FlowL7DataPtrFree(&f);
StreamTcpFreeConfig(TRUE);
FLOW_DESTROY(&f);
SCFree(p);
return result;
}

@ -398,28 +398,31 @@ int DetectIcmpIdMatchTest02 (void) {
0x51, 0xa6, 0xbb, 0x35, 0x59, 0x8a, 0x5a, 0xe2,
0x00, 0x14, 0x00, 0x00 };
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
Signature *s = NULL;
DecodeThreadVars dtv;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
IPV4Hdr ip4h;
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ip4h, 0, sizeof(IPV4Hdr));
memset(&dtv, 0, sizeof(DecodeThreadVars));
memset(&th_v, 0, sizeof(ThreadVars));
FlowInitConfig(FLOW_QUIET);
p.src.addr_data32[0] = 0x01020304;
p.dst.addr_data32[0] = 0x04030201;
p->src.addr_data32[0] = 0x01020304;
p->dst.addr_data32[0] = 0x04030201;
ip4h.ip_src.s_addr = p.src.addr_data32[0];
ip4h.ip_dst.s_addr = p.dst.addr_data32[0];
p.ip4h = &ip4h;
ip4h.ip_src.s_addr = p->src.addr_data32[0];
ip4h.ip_dst.s_addr = p->dst.addr_data32[0];
p->ip4h = &ip4h;
DecodeICMPV4(&th_v, &dtv, &p, raw_icmpv4, sizeof(raw_icmpv4), NULL);
DecodeICMPV4(&th_v, &dtv, p, raw_icmpv4, sizeof(raw_icmpv4), NULL);
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL) {
@ -436,8 +439,8 @@ int DetectIcmpIdMatchTest02 (void) {
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
if (PacketAlertCheck(&p, 1)) {
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
if (PacketAlertCheck(p, 1)) {
printf("sid 1 alerted, but should not have: ");
goto cleanup;
}
@ -453,6 +456,7 @@ cleanup:
FlowShutdown();
end:
SCFree(p);
return result;
}
#endif /* UNITTESTS */

@ -266,7 +266,9 @@ int IpOptsTestParse02 (void) {
* \retval 0 on failure
*/
int IpOptsTestParse03 (void) {
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int ret = 0;
DetectIpOptsData *de = NULL;
@ -274,13 +276,14 @@ int IpOptsTestParse03 (void) {
IPV4Hdr ip4h;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ip4h, 0, sizeof(IPV4Hdr));
p.ip4h = &ip4h;
p.IPV4_OPTS[0].type = IPV4_OPT_RR;
p->ip4h = &ip4h;
p->IPV4_OPTS[0].type = IPV4_OPT_RR;
p.IPV4_OPTS_CNT++;
p->IPV4_OPTS_CNT++;
de = DetectIpOptsParse("rr");
@ -294,14 +297,17 @@ int IpOptsTestParse03 (void) {
sm->type = DETECT_IPOPTS;
sm->ctx = (void *)de;
ret = DetectIpOptsMatch(&tv,NULL,&p,NULL,sm);
ret = DetectIpOptsMatch(&tv,NULL,p,NULL,sm);
if(ret)
if(ret) {
SCFree(p);
return 1;
}
error:
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
}
@ -312,7 +318,9 @@ error:
* \retval 0 on failure
*/
int IpOptsTestParse04 (void) {
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
ThreadVars tv;
int ret = 0;
DetectIpOptsData *de = NULL;
@ -320,13 +328,14 @@ int IpOptsTestParse04 (void) {
IPV4Hdr ip4h;
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ip4h, 0, sizeof(IPV4Hdr));
p.ip4h = &ip4h;
p.IPV4_OPTS[0].type = IPV4_OPT_RR;
p->ip4h = &ip4h;
p->IPV4_OPTS[0].type = IPV4_OPT_RR;
p.IPV4_OPTS_CNT++;
p->IPV4_OPTS_CNT++;
de = DetectIpOptsParse("lsrr");
@ -340,14 +349,17 @@ int IpOptsTestParse04 (void) {
sm->type = DETECT_IPOPTS;
sm->ctx = (void *)de;
ret = DetectIpOptsMatch(&tv,NULL,&p,NULL,sm);
ret = DetectIpOptsMatch(&tv,NULL,p,NULL,sm);
if(ret)
if(ret) {
SCFree(p);
return 1;
}
error:
if (de) SCFree(de);
if (sm) SCFree(sm);
SCFree(p);
return 0;
}
#endif /* UNITTESTS */

@ -2695,16 +2695,19 @@ int SigTestBidirec04 (void) {
0x6b,0x65,0x65,0x70,0x2d,0x61,0x6c,0x69,
0x76,0x65,0x0d,0x0a,0x0d,0x0a }; /* end rawpkt1_ether */
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
DecodeThreadVars dtv;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx;
memset(&th_v, 0, sizeof(th_v));
memset(&p, 0, sizeof(p));
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
FlowInitConfig(FLOW_QUIET);
DecodeEthernet(&th_v, &dtv, &p, rawpkt1_ether, sizeof(rawpkt1_ether), NULL);
DecodeEthernet(&th_v, &dtv, p, rawpkt1_ether, sizeof(rawpkt1_ether), NULL);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
/* At this point we have a list of 4 signatures. The last one
@ -2713,11 +2716,11 @@ int SigTestBidirec04 (void) {
SigGroupBuild(de_ctx);
//PatternMatchPrepare(mpm_ctx, MPM_B2G);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
/* only sid 2 should match with a packet going to 192.168.1.1 port 80 */
if (PacketAlertCheck(&p, 1) <= 0 && PacketAlertCheck(&p, 3) <= 0 &&
PacketAlertCheck(&p, 2) == 1) {
if (PacketAlertCheck(p, 1) <= 0 && PacketAlertCheck(p, 3) <= 0 &&
PacketAlertCheck(p, 2) == 1) {
result = 1;
}
@ -2732,6 +2735,7 @@ end:
DetectEngineCtxFree(de_ctx);
}
SCFree(p);
return result;
}

@ -388,7 +388,9 @@ static int DetectStreamSizeParseTest03 (void) {
TcpSession ssn;
ThreadVars tv;
DetectEngineThreadCtx dtx;
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
Signature s;
SigMatch sm;
TcpStream client;
@ -398,7 +400,8 @@ static int DetectStreamSizeParseTest03 (void) {
memset(&ssn, 0, sizeof(TcpSession));
memset(&tv, 0, sizeof(ThreadVars));
memset(&dtx, 0, sizeof(DetectEngineThreadCtx));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&s, 0, sizeof(Signature));
memset(&sm, 0, sizeof(SigMatch));
memset(&client, 0, sizeof(TcpStream));
@ -410,22 +413,26 @@ static int DetectStreamSizeParseTest03 (void) {
if (!(sd->flags & STREAM_SIZE_CLIENT)) {
printf("sd->flags not STREAM_SIZE_CLIENT: ");
DetectStreamSizeFree(sd);
SCFree(p);
return 0;
}
if (sd->mode != DETECTSSIZE_GT) {
printf("sd->mode not DETECTSSIZE_GT: ");
DetectStreamSizeFree(sd);
SCFree(p);
return 0;
}
if (sd->ssize != 8) {
printf("sd->ssize is %"PRIu32", not 8: ", sd->ssize);
DetectStreamSizeFree(sd);
SCFree(p);
return 0;
}
} else {
printf("sd == NULL: ");
SCFree(p);
return 0;
}
@ -433,15 +440,16 @@ static int DetectStreamSizeParseTest03 (void) {
client.isn = 10;
ssn.client = client;
f.protoctx = &ssn;
p.flow = &f;
p.tcph = &tcph;
p->flow = &f;
p->tcph = &tcph;
sm.ctx = sd;
result = DetectStreamSizeMatch(&tv, &dtx, &p, &s, &sm);
result = DetectStreamSizeMatch(&tv, &dtx, p, &s, &sm);
if (result == 0) {
printf("result 0 != 1: ");
}
DetectStreamSizeFree(sd);
SCFree(p);
return result;
}
@ -457,7 +465,9 @@ static int DetectStreamSizeParseTest04 (void) {
TcpSession ssn;
ThreadVars tv;
DetectEngineThreadCtx dtx;
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
Signature s;
SigMatch sm;
TcpStream client;
@ -467,7 +477,8 @@ static int DetectStreamSizeParseTest04 (void) {
memset(&ssn, 0, sizeof(TcpSession));
memset(&tv, 0, sizeof(ThreadVars));
memset(&dtx, 0, sizeof(DetectEngineThreadCtx));
memset(&p, 0, SIZE_OF_PACKET);
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&s, 0, sizeof(Signature));
memset(&sm, 0, sizeof(SigMatch));
memset(&client, 0, sizeof(TcpStream));
@ -476,22 +487,28 @@ static int DetectStreamSizeParseTest04 (void) {
sd = DetectStreamSizeParse(" client , > , 8 ");
if (sd != NULL) {
if (!(sd->flags & STREAM_SIZE_CLIENT) && sd->mode != DETECTSSIZE_GT && sd->ssize != 8)
return 0;
if (!(sd->flags & STREAM_SIZE_CLIENT) && sd->mode != DETECTSSIZE_GT && sd->ssize != 8) {
SCFree(p);
return 0;
}
} else
{
SCFree(p);
return 0;
}
client.next_seq = 20;
client.isn = 12;
ssn.client = client;
f.protoctx = &ssn;
p.flow = &f;
p.ip4h = &ip4h;
p->flow = &f;
p->ip4h = &ip4h;
sm.ctx = sd;
if (!DetectStreamSizeMatch(&tv, &dtx, &p, &s, &sm))
if (!DetectStreamSizeMatch(&tv, &dtx, p, &s, &sm))
result = 1;
SCFree(p);
return result;
}
#endif /* UNITTESTS */

@ -495,7 +495,9 @@ end:
static int DetectTtlTestSig1(void) {
Packet p;
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
Signature *s = NULL;
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx;
@ -503,14 +505,15 @@ static int DetectTtlTestSig1(void) {
IPV4Hdr ip4h;
memset(&th_v, 0, sizeof(th_v));
memset(&p, 0, sizeof(p));
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
memset(&ip4h, 0, sizeof(ip4h));
p.src.family = AF_INET;
p.dst.family = AF_INET;
p.proto = IPPROTO_TCP;
p->src.family = AF_INET;
p->dst.family = AF_INET;
p->proto = IPPROTO_TCP;
ip4h.ip_ttl = 15;
p.ip4h = &ip4h;
p->ip4h = &ip4h;
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL) {
@ -542,17 +545,17 @@ static int DetectTtlTestSig1(void) {
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
if (PacketAlertCheck(&p, 1)) {
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) {
} else if (PacketAlertCheck(p, 2) == 0) {
printf("sid 2 did not alert, but should have: ");
goto cleanup;
} else if (PacketAlertCheck(&p, 3) == 0) {
} else if (PacketAlertCheck(p, 3) == 0) {
printf("sid 3 did not alert, but should have: ");
goto cleanup;
} else if (PacketAlertCheck(&p, 4) == 0) {
} else if (PacketAlertCheck(p, 4) == 0) {
printf("sid 4 did not alert, but should have: ");
goto cleanup;
}
@ -567,6 +570,7 @@ cleanup:
DetectEngineCtxFree(de_ctx);
end:
SCFree(p);
return result;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -2755,24 +2755,28 @@ static int B2gCudaTest01(void)
pb->packets_offset_buffer[0] = 0;
pb->packets_payload_offset_buffer[0] = 0;
Packet p;
memset(&p, 0, SIZE_OF_PACKET);
pb->packets_address_buffer[0] = &p;
p.payload_len = strlen(string);
Packet *p = SCMalloc(SIZE_OF_PACKET);
if (p == NULL)
return 0;
memset(p, 0, SIZE_OF_PACKET);
p->pkt = (uint8_t *)(p + 1);
pb->packets_address_buffer[0] = p;
p->payload_len = strlen(string);
B2gCudaMpmDispatcher(NULL, (Packet *)pb, tctx, NULL, NULL);
result &= (p.mpm_offsets[0] == 4);
result &= (p.mpm_offsets[1] == 1);
result &= (p.mpm_offsets[2] == 5);
result &= (p.mpm_offsets[3] == 9);
result &= (p.mpm_offsets[4] == 13);
result &= (p->mpm_offsets[0] == 4);
result &= (p->mpm_offsets[1] == 1);
result &= (p->mpm_offsets[2] == 5);
result &= (p->mpm_offsets[3] == 9);
result &= (p->mpm_offsets[4] == 13);
end:
SCCudaPBDeAllocSCCudaPBPacketsBuffer(pb);
B2gCudaMpmDispThreadDeInit(NULL, (void *)tctx);
B2gCudaDestroyCtx(&mpm_ctx);
B2gCudaThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx);
SCFree(p);
return result;
}

Loading…
Cancel
Save