Adapt Flow subsys init function to be able to initialize quietly for us in unit tests. Add flow to PPP unit tests. Fixes a floating point exception error.

remotes/origin/master-1.0.x
Victor Julien 16 years ago
parent 416bdd543a
commit 9854c19a88

@ -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);

Loading…
Cancel
Save