Merge branch 'victor_local'

remotes/origin/master-1.0.x
Victor Julien 16 years ago
commit c35dfe1bdb

@ -1,10 +1,14 @@
/* Copyright (c) 2009 Open Infosec Foundation
* Written by Breno Silva Pinto <breno.silva@gmail.com> */
#include "eidps.h"
#include "decode.h"
#include "decode-ppp.h"
#include "decode-events.h"
#include "flow.h"
#include "util-unittest.h"
void DecodePPP(ThreadVars *t, Packet *p, u_int8_t *pkt, u_int16_t len, PacketQueue *pq)
@ -166,8 +170,12 @@ static int DecodePPPtest03 (void) {
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, sizeof(Packet));
FlowInitConfig(FLOW_QUIET);
DecodePPP(&tv, &p, raw_ppp, sizeof(raw_ppp), NULL);
FlowShutdown();
if(p.ppph == NULL) {
return 0;
}
@ -207,8 +215,12 @@ static int DecodePPPtest04 (void) {
memset(&tv, 0, sizeof(ThreadVars));
memset(&p, 0, sizeof(Packet));
FlowInitConfig(FLOW_QUIET);
DecodePPP(&tv, &p, raw_ppp, sizeof(raw_ppp), NULL);
FlowShutdown();
if(p.ppph == NULL) {
return 0;
}

@ -907,7 +907,7 @@ int main(int argc, char **argv)
}
printf("Preallocating packets... done\n");
FlowInitConfig();
FlowInitConfig(FLOW_VERBOSE);
/* Initialize and set thread detached attribute */
pthread_attr_init(&attr);

@ -266,9 +266,10 @@ void FlowHandlePacket (ThreadVars *th_v, Packet *p)
#define FLOW_DEFAULT_PREALLOC 10000
/* Not Thread safe */
void FlowInitConfig (void)
void FlowInitConfig (char quiet)
{
printf("Initializing Flow:\n");
if (quiet == FALSE)
printf("Initializing Flow:\n");
memset(&flow_config, 0, sizeof(flow_config));
memset(&flow_spare_q, 0, sizeof(flow_spare_q));
@ -297,8 +298,9 @@ void FlowInitConfig (void)
memset(flow_hash, 0, flow_config.hash_size * sizeof(FlowBucket));
flow_config.memuse += (flow_config.hash_size * sizeof(FlowBucket));
printf("* Allocated %u bytes of memory for the flow hash... %u buckets of size %u\n",
flow_config.memuse, flow_config.hash_size, sizeof(FlowBucket));
if (quiet == FALSE)
printf("* Allocated %u bytes of memory for the flow hash... %u buckets of size %u\n",
flow_config.memuse, flow_config.hash_size, sizeof(FlowBucket));
/* pre allocate flows */
u_int32_t i = 0;
@ -310,10 +312,13 @@ void FlowInitConfig (void)
}
FlowEnqueue(&flow_spare_q,f);
}
printf("* Preallocated %u flows of size %u\n",
flow_spare_q.len, sizeof(Flow));
printf("* Flow memory usage: %u bytes. Maximum: %u\n",
flow_config.memuse, flow_config.memcap);
if (quiet == FALSE) {
printf("* Preallocated %u flows of size %u\n",
flow_spare_q.len, sizeof(Flow));
printf("* Flow memory usage: %u bytes. Maximum: %u\n",
flow_config.memuse, flow_config.memcap);
}
}
/* Not Thread safe */

@ -6,6 +6,9 @@
#include "decode.h"
#include "util-var.h"
#define FLOW_QUIET TRUE
#define FLOW_VERBOSE FALSE
/* pkt flow flags */
#define FLOW_PKT_TOSERVER 0x01
#define FLOW_PKT_TOCLIENT 0x02
@ -79,7 +82,7 @@ typedef struct Flow_
} Flow;
void FlowHandlePacket (ThreadVars *, Packet *);
void FlowInitConfig (void);
void FlowInitConfig (char);
void FlowPrintFlows (void);
void FlowShutdown(void);
void FlowSetIPOnlyFlag(Flow *, char);

@ -328,6 +328,63 @@ end:
return retval;
}
static int PoolTestInit06 (void) {
int retval = 0;
void *data = NULL;
Pool *p = PoolInit(1,0,PoolTestAlloc,NULL,PoolTestFree);
if (p == NULL)
goto end;
if (p->allocated != 0) {
printf("p->allocated 0 != %u: ", p->allocated);
retval = 0;
goto end;
}
data = PoolGet(p);
if (data == NULL) {
printf("PoolGet returned NULL: ");
retval = 0;
goto end;
}
if (p->allocated != 1) {
printf("p->allocated 1 != %u: ", p->allocated);
retval = 0;
goto end;
}
data = PoolGet(p);
if (data != NULL) {
printf("PoolGet returned %p, expected NULL: ");
retval = 0;
goto end;
}
PoolReturn(p,data);
data = NULL;
if (p->allocated != 1) {
printf("p->allocated 1 != %u: ", p->allocated);
retval = 0;
goto end;
}
if (p->alloc_list_size != 1) {
printf("p->alloc_list_size 1 != %u: ", p->alloc_list_size);
retval = 0;
goto end;
}
retval = 1;
end:
if (data != NULL)
free(data);
if (p != NULL)
PoolFree(p);
return retval;
}
void PoolRegisterTests(void) {
UtRegisterTest("PoolTestInit01", PoolTestInit01, 1);
@ -335,5 +392,6 @@ void PoolRegisterTests(void) {
UtRegisterTest("PoolTestInit03", PoolTestInit03, 1);
UtRegisterTest("PoolTestInit04", PoolTestInit04, 1);
UtRegisterTest("PoolTestInit05", PoolTestInit05, 1);
UtRegisterTest("PoolTestInit06", PoolTestInit06, 1);
}

Loading…
Cancel
Save