Update all flow referencing to use the new FlowReference and FlowDeReference

macros.
pull/103/merge
Anoop Saldanha 13 years ago committed by Victor Julien
parent 6c68f86b8c
commit 3d74fa964a

@ -30,6 +30,7 @@
#include "stream-tcp-reassemble.h" #include "stream-tcp-reassemble.h"
#include "stream-tcp-private.h" #include "stream-tcp-private.h"
#include "flow.h" #include "flow.h"
#include "flow-util.h"
#include "util-debug.h" #include "util-debug.h"
#include "util-print.h" #include "util-print.h"
@ -258,17 +259,13 @@ int AppLayerHandleTCPMsg(AlpProtoDetectThreadCtx *dp_ctx, StreamMsg *smsg)
} }
} }
/* flow is free again */ FlowDeReference(&smsg->flow);
FlowDecrUsecnt(smsg->flow);
/* dereference the flow */
smsg->flow = NULL;
} else { /* no ssn ptr */ } else { /* no ssn ptr */
/* if there is no ssn ptr we won't /* if there is no ssn ptr we won't
* be inspecting this msg in detect * be inspecting this msg in detect
* so return it to the pool. */ * so return it to the pool. */
/* flow is free again */ FlowDeReference(&smsg->flow);
FlowDecrUsecnt(smsg->flow);
/* return the used message to the queue */ /* return the used message to the queue */
StreamMsgReturnToPool(smsg); StreamMsgReturnToPool(smsg);

@ -1426,8 +1426,6 @@ int SigMatchSignatures(ThreadVars *th_v, DetectEngineCtx *de_ctx, DetectEngineTh
SCLogDebug("STREAM_EOF set"); SCLogDebug("STREAM_EOF set");
} }
FlowIncrUsecnt(p->flow);
FLOWLOCK_WRLOCK(p->flow); FLOWLOCK_WRLOCK(p->flow);
{ {
/* live ruleswap check for flow updates */ /* live ruleswap check for flow updates */
@ -1985,8 +1983,6 @@ end:
StreamMsgReturnListToPool(smsg); StreamMsgReturnListToPool(smsg);
FLOWLOCK_UNLOCK(p->flow); FLOWLOCK_UNLOCK(p->flow);
FlowDecrUsecnt(p->flow);
} }
PACKET_PROFILING_DETECT_END(p, PROF_DETECT_CLEANUP); PACKET_PROFILING_DETECT_END(p, PROF_DETECT_CLEANUP);

@ -442,8 +442,6 @@ static Flow *FlowGetNew(Packet *p) {
/* flow is initialized (recylced) but *unlocked* */ /* flow is initialized (recylced) but *unlocked* */
} }
FlowIncrUsecnt(f);
FLOWLOCK_WRLOCK(f); FLOWLOCK_WRLOCK(f);
return f; return f;
} }
@ -488,6 +486,8 @@ Flow *FlowGetFlowFromHash (Packet *p)
fb->head = f; fb->head = f;
fb->tail = f; fb->tail = f;
FlowReference(&p->flow, f);
/* got one, now lock, initialize and return */ /* got one, now lock, initialize and return */
FlowInit(f,p); FlowInit(f,p);
f->fb = fb; f->fb = fb;
@ -523,6 +523,8 @@ Flow *FlowGetFlowFromHash (Packet *p)
f->hprev = pf; f->hprev = pf;
FlowReference(&p->flow, f);
/* initialize and return */ /* initialize and return */
FlowInit(f,p); FlowInit(f,p);
f->fb = fb; f->fb = fb;
@ -550,8 +552,9 @@ Flow *FlowGetFlowFromHash (Packet *p)
fb->head->hprev = f; fb->head->hprev = f;
fb->head = f; fb->head = f;
FlowReference(&p->flow, f);
/* found our flow, lock & return */ /* found our flow, lock & return */
FlowIncrUsecnt(f);
FLOWLOCK_WRLOCK(f); FLOWLOCK_WRLOCK(f);
FBLOCK_UNLOCK(fb); FBLOCK_UNLOCK(fb);
FlowHashCountUpdate; FlowHashCountUpdate;
@ -561,7 +564,7 @@ Flow *FlowGetFlowFromHash (Packet *p)
} }
/* lock & return */ /* lock & return */
FlowIncrUsecnt(f); FlowReference(&p->flow, f);
FLOWLOCK_WRLOCK(f); FLOWLOCK_WRLOCK(f);
FBLOCK_UNLOCK(fb); FBLOCK_UNLOCK(fb);
FlowHashCountUpdate; FlowHashCountUpdate;

@ -113,8 +113,7 @@ static inline Packet *FlowForceReassemblyPseudoPacketSetup(Packet *p,
{ {
p->datalink = DLT_RAW; p->datalink = DLT_RAW;
p->proto = IPPROTO_TCP; p->proto = IPPROTO_TCP;
p->flow = f; FlowReference(&p->flow, f);
FlowIncrUsecnt(f);
p->flags |= PKT_STREAM_EST; p->flags |= PKT_STREAM_EST;
p->flags |= PKT_STREAM_EOF; p->flags |= PKT_STREAM_EOF;
p->flags |= PKT_HAS_FLOW; p->flags |= PKT_HAS_FLOW;

@ -127,14 +127,18 @@
#define FLOW_CHECK_MEMCAP(size) \ #define FLOW_CHECK_MEMCAP(size) \
((((uint64_t)SC_ATOMIC_GET(flow_memuse) + (uint64_t)(size)) <= flow_config.memcap)) ((((uint64_t)SC_ATOMIC_GET(flow_memuse) + (uint64_t)(size)) <= flow_config.memcap))
#define FlowReference(dst_f_ptr, f) do { \ #define FlowReference(dst_f_ptr, f) do { \
FlowIncrUsecnt((f)); \ if ((f) != NULL) { \
*(dst_f_ptr) = f; \ FlowIncrUsecnt((f)); \
*(dst_f_ptr) = f; \
} \
} while (0) } while (0)
#define FlowDeReference(src_f_ptr) do { \ #define FlowDeReference(src_f_ptr) do { \
FlowDecrUsecnt(*(src_f_ptr)); \ if (*(src_f_ptr) != NULL) { \
*(src_f_ptr) = NULL; \ FlowDecrUsecnt(*(src_f_ptr)); \
*(src_f_ptr) = NULL; \
} \
} while (0) } while (0)
Flow *FlowAlloc(void); Flow *FlowAlloc(void);

@ -310,7 +310,6 @@ void FlowHandlePacket (ThreadVars *tv, Packet *p)
FLOWLOCK_UNLOCK(f); FLOWLOCK_UNLOCK(f);
/* set the flow in the packet */ /* set the flow in the packet */
p->flow = f;
p->flags |= PKT_HAS_FLOW; p->flags |= PKT_HAS_FLOW;
return; return;
} }

@ -1714,11 +1714,9 @@ static void StreamTcpSetupMsg(TcpSession *ssn, TcpStream *stream, Packet *p,
} }
smsg->data.data_len = 0; smsg->data.data_len = 0;
smsg->flow = p->flow; FlowReference(&smsg->flow, p->flow);
BUG_ON(smsg->flow == NULL); BUG_ON(smsg->flow == NULL);
FlowIncrUsecnt(smsg->flow);
SCLogDebug("smsg %p", smsg); SCLogDebug("smsg %p", smsg);
SCReturn; SCReturn;
} }

@ -4494,9 +4494,7 @@ Packet *StreamTcpPseudoSetup(Packet *parent, uint8_t *pkt, uint32_t len)
p->ts.tv_sec = parent->ts.tv_sec; p->ts.tv_sec = parent->ts.tv_sec;
p->ts.tv_usec = parent->ts.tv_usec; p->ts.tv_usec = parent->ts.tv_usec;
p->flow = parent->flow; FlowReference(&p->flow, parent->flow);
FlowIncrUsecnt(p->flow);
/* set tunnel flags */ /* set tunnel flags */
/* tell new packet it's part of a tunnel */ /* tell new packet it's part of a tunnel */

Loading…
Cancel
Save