macros.
#include "stream-tcp-reassemble.h"
#include "stream-tcp-private.h"
#include "flow.h"
+#include "flow-util.h"
#include "util-debug.h"
#include "util-print.h"
}
}
- /* flow is free again */
- FlowDecrUsecnt(smsg->flow);
- /* dereference the flow */
- smsg->flow = NULL;
+ FlowDeReference(&smsg->flow);
} else { /* no ssn ptr */
/* if there is no ssn ptr we won't
* be inspecting this msg in detect
* so return it to the pool. */
- /* flow is free again */
- FlowDecrUsecnt(smsg->flow);
+ FlowDeReference(&smsg->flow);
/* return the used message to the queue */
StreamMsgReturnToPool(smsg);
SCLogDebug("STREAM_EOF set");
}
- FlowIncrUsecnt(p->flow);
-
FLOWLOCK_WRLOCK(p->flow);
{
/* live ruleswap check for flow updates */
StreamMsgReturnListToPool(smsg);
FLOWLOCK_UNLOCK(p->flow);
-
- FlowDecrUsecnt(p->flow);
}
PACKET_PROFILING_DETECT_END(p, PROF_DETECT_CLEANUP);
/* flow is initialized (recylced) but *unlocked* */
}
- FlowIncrUsecnt(f);
-
FLOWLOCK_WRLOCK(f);
return f;
}
fb->head = f;
fb->tail = f;
+ FlowReference(&p->flow, f);
+
/* got one, now lock, initialize and return */
FlowInit(f,p);
f->fb = fb;
f->hprev = pf;
+ FlowReference(&p->flow, f);
+
/* initialize and return */
FlowInit(f,p);
f->fb = fb;
fb->head->hprev = f;
fb->head = f;
+ FlowReference(&p->flow, f);
+
/* found our flow, lock & return */
- FlowIncrUsecnt(f);
FLOWLOCK_WRLOCK(f);
FBLOCK_UNLOCK(fb);
FlowHashCountUpdate;
}
/* lock & return */
- FlowIncrUsecnt(f);
+ FlowReference(&p->flow, f);
FLOWLOCK_WRLOCK(f);
FBLOCK_UNLOCK(fb);
FlowHashCountUpdate;
{
p->datalink = DLT_RAW;
p->proto = IPPROTO_TCP;
- p->flow = f;
- FlowIncrUsecnt(f);
+ FlowReference(&p->flow, f);
p->flags |= PKT_STREAM_EST;
p->flags |= PKT_STREAM_EOF;
p->flags |= PKT_HAS_FLOW;
#define FLOW_CHECK_MEMCAP(size) \
((((uint64_t)SC_ATOMIC_GET(flow_memuse) + (uint64_t)(size)) <= flow_config.memcap))
-#define FlowReference(dst_f_ptr, f) do { \
- FlowIncrUsecnt((f)); \
- *(dst_f_ptr) = f; \
+#define FlowReference(dst_f_ptr, f) do { \
+ if ((f) != NULL) { \
+ FlowIncrUsecnt((f)); \
+ *(dst_f_ptr) = f; \
+ } \
} while (0)
-#define FlowDeReference(src_f_ptr) do { \
- FlowDecrUsecnt(*(src_f_ptr)); \
- *(src_f_ptr) = NULL; \
+#define FlowDeReference(src_f_ptr) do { \
+ if (*(src_f_ptr) != NULL) { \
+ FlowDecrUsecnt(*(src_f_ptr)); \
+ *(src_f_ptr) = NULL; \
+ } \
} while (0)
Flow *FlowAlloc(void);
FLOWLOCK_UNLOCK(f);
/* set the flow in the packet */
- p->flow = f;
p->flags |= PKT_HAS_FLOW;
return;
}
}
smsg->data.data_len = 0;
- smsg->flow = p->flow;
+ FlowReference(&smsg->flow, p->flow);
BUG_ON(smsg->flow == NULL);
- FlowIncrUsecnt(smsg->flow);
-
SCLogDebug("smsg %p", smsg);
SCReturn;
}
p->ts.tv_sec = parent->ts.tv_sec;
p->ts.tv_usec = parent->ts.tv_usec;
- p->flow = parent->flow;
- FlowIncrUsecnt(p->flow);
-
+ FlowReference(&p->flow, parent->flow);
/* set tunnel flags */
/* tell new packet it's part of a tunnel */