From a4ad7939d2aa6f2cec8d85859024f9f64d3d4866 Mon Sep 17 00:00:00 2001 From: Gurvinder Singh Date: Tue, 1 Sep 2009 18:49:18 +0300 Subject: [PATCH] proto specific free function --- src/flow.c | 34 +++++++++++++++++++++------------- src/flow.h | 16 +++++++++------- src/stream-tcp.c | 2 ++ src/stream-tcp.h | 1 - 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/flow.c b/src/flow.c index 186036adc9..f712f3de8c 100644 --- a/src/flow.c +++ b/src/flow.c @@ -25,7 +25,6 @@ #include "flow-var.h" #include "flow-private.h" #include "util-unittest.h" -#include "stream-tcp.h" //#define FLOW_DEFAULT_HASHSIZE 262144 #define FLOW_DEFAULT_HASHSIZE 65536 @@ -43,7 +42,8 @@ static int FlowUpdateSpareFlows(void); int FlowSetProtoTimeout(uint8_t , uint32_t ,uint32_t ); int FlowSetProtoEmergencyTimeout(uint8_t , uint32_t ,uint32_t ); static int FlowGetProtoMapping(uint8_t ); -int FlowSetProtoFreeFunc(uint8_t, Flow *f, void (*Free)(void *)); +static int FlowClearMemory(Flow *,uint8_t ); +int FlowSetProtoFreeFunc(uint8_t, void (*Free)(void *)); /** \brief Update the flows position in the queue's * \param f Flow to requeue. * @@ -156,7 +156,7 @@ static int FlowPrune (FlowQueue *q, struct timeval *ts) mutex_unlock(&f->fb->m); f->fb = NULL; - FlowSetProtoFreeFunc (f->proto, f, protocols[proto_map].Freefunc); + FlowClearMemory (f, proto_map); /* move to spare list */ FlowRequeue(f, q, &flow_spare_q); @@ -515,35 +515,43 @@ void FlowInitProtocols(void) { protocols[0].est_timeout = FLOW_DEFAULT_EST_TIMEOUT; protocols[0].emerg_new_timeout = FLOW_DEFAULT_EMERG_NEW_TIMEOUT; protocols[0].emerg_est_timeout = FLOW_DEFAULT_EMERG_EST_TIMEOUT; - protocols[0].Freefunc = ""; + protocols[0].Freefunc = NULL; /*TCP*/ protocols[1].new_timeout = FLOW_IPPROTO_TCP_NEW_TIMEOUT; protocols[1].est_timeout = FLOW_IPPROTO_TCP_EST_TIMEOUT; protocols[1].emerg_new_timeout = FLOW_IPPROTO_TCP_EMERG_NEW_TIMEOUT; protocols[1].emerg_est_timeout = FLOW_IPPROTO_TCP_EMERG_EST_TIMEOUT; - protocols[1].Freefunc = StreamTcpSessionPoolFree; + protocols[1].Freefunc = NULL; /*UDP*/ protocols[2].new_timeout = FLOW_IPPROTO_UDP_NEW_TIMEOUT; protocols[2].est_timeout = FLOW_IPPROTO_UDP_EST_TIMEOUT; protocols[2].emerg_new_timeout = FLOW_IPPROTO_UDP_EMERG_NEW_TIMEOUT; protocols[2].emerg_est_timeout = FLOW_IPPROTO_UDP_EMERG_EST_TIMEOUT; - protocols[2].Freefunc = ""; + protocols[2].Freefunc = NULL; /*ICMP*/ protocols[3].new_timeout = FLOW_IPPROTO_ICMP_NEW_TIMEOUT; protocols[3].est_timeout = FLOW_IPPROTO_ICMP_EST_TIMEOUT; protocols[3].emerg_new_timeout = FLOW_IPPROTO_ICMP_EMERG_NEW_TIMEOUT; protocols[3].emerg_est_timeout = FLOW_IPPROTO_ICMP_EMERG_EST_TIMEOUT; - protocols[3].Freefunc = ""; + protocols[3].Freefunc = NULL; } -int FlowSetProtoFreeFunc (uint8_t proto, Flow *f, void (*Free)(void *)) { - /*XXX GS WIP*/ - //uint8_t proto_map; - //proto_map = FlowGetProtoMapping(proto); - Free(f->stream); +static int FlowClearMemory(Flow* f, uint8_t proto_map) { + /*This check should be removed later*/ + if (protocols[proto_map].Freefunc != NULL) + protocols[proto_map].Freefunc(f->stream); + memset(f, 0, sizeof(Flow)); - //FlowSetProtoFreeFunc(f->proto, ); + return 1; +} + +int FlowSetProtoFreeFunc (uint8_t proto, void (*Free)(void *)) { + + uint8_t proto_map; + proto_map = FlowGetProtoMapping(proto); + + protocols[proto_map].Freefunc = Free; return 1; } diff --git a/src/flow.h b/src/flow.h index f297a7f8b5..9754b32c69 100644 --- a/src/flow.h +++ b/src/flow.h @@ -84,12 +84,12 @@ typedef struct Flow_ struct FlowBucket_ *fb; } Flow; -/*enum { - NEW = 0, - ESTABLISHED, - EMERG_NEW, - EMERG_ESTABLISHED, -};*/ +enum { + FLOW_PROTO_DEFAULT = 0, + FLOW_PROTO_TCP, + FLOW_PROTO_UDP, + FLOW_PROTO_ICMP, +}; typedef struct Protocols_ { uint32_t new_timeout; @@ -110,7 +110,9 @@ void *FlowManagerThread(void *td); void FlowManagerThreadSpawn(void); void FlowRegisterTests (void); -int FlowSetProtoTimout(uint8_t ,uint8_t, uint32_t ,uint32_t ); +int FlowSetProtoTimout(uint8_t ,uint32_t ,uint32_t ); +int FlowSetProtoEmergencyTimeout(uint8_t ,uint32_t ,uint32_t ); +int FlowSetProtoFreeFunc (uint8_t , void (*Free)(void *)) #endif /* __FLOW_H__ */ diff --git a/src/stream-tcp.c b/src/stream-tcp.c index 0d6748dec6..80d5ec41e0 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -158,6 +158,8 @@ void StreamTcpInitConfig(char quiet) { } pthread_mutex_init(&ssn_pool_mutex, NULL); + + FlowSetProtoFreeFunc(IPPROTO_TCP, StreamTcpSessionPoolFree); } /** \brief The function is used to to fetch a TCP session from the diff --git a/src/stream-tcp.h b/src/stream-tcp.h index 57a07f189e..6b97195a71 100644 --- a/src/stream-tcp.h +++ b/src/stream-tcp.h @@ -16,7 +16,6 @@ typedef struct TcpStreamCnf_ { TcpStreamCnf stream_config; void TmModuleStreamTcpRegister (void); void StreamTcpInitConfig (char); -void StreamTcpSessionPoolFree(void *); #endif /* __STREAM_TCP_H__ */