Update Flow lookup functions to get a flow reference during lookup.
This reference is set under the FlowBucket lock.
This paves the way to not getting a flow lock during lookups.
return f;
}
-Flow *FlowGetFlowFromHashByPacket(const Packet *p)
+Flow *FlowGetFlowFromHashByPacket(const Packet *p, Flow **dest)
{
Flow *f = NULL;
f->fb = fb;
/* update the last seen timestamp of this flow */
COPY_TIMESTAMP(&p->ts,&f->lastts);
+ FlowReference(dest, f);
}
FBLOCK_UNLOCK(fb);
*
* \retval f flow or NULL if not found
*/
-Flow *FlowLookupFlowFromHash(const Packet *p)
+Flow *FlowLookupFlowFromHash(const Packet *p, Flow **dest)
{
Flow *f = NULL;
FLOWLOCK_WRLOCK(f);
/* update the last seen timestamp of this flow */
COPY_TIMESTAMP(&p->ts,&f->lastts);
+ FlowReference(dest, f);
FBLOCK_UNLOCK(fb);
return f;
FLOWLOCK_WRLOCK(f);
/* update the last seen timestamp of this flow */
COPY_TIMESTAMP(&p->ts,&f->lastts);
+ FlowReference(dest, f);
FBLOCK_UNLOCK(fb);
return f;
*
* \retval f *LOCKED* flow or NULL
*/
-Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *p)
+Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *p, Flow **dest)
{
Flow *f = NULL;
/* update the last seen timestamp of this flow */
COPY_TIMESTAMP(&p->ts,&f->lastts);
+ FlowReference(dest, f);
FBLOCK_UNLOCK(fb);
return f;
/* update the last seen timestamp of this flow */
COPY_TIMESTAMP(&p->ts,&f->lastts);
+ FlowReference(dest, f);
FBLOCK_UNLOCK(fb);
return f;
FLOWLOCK_WRLOCK(f);
/* update the last seen timestamp of this flow */
COPY_TIMESTAMP(&p->ts,&f->lastts);
+ FlowReference(dest, f);
FBLOCK_UNLOCK(fb);
return f;
FLOWLOCK_WRLOCK(f);
/* update the last seen timestamp of this flow */
COPY_TIMESTAMP(&p->ts,&f->lastts);
+ FlowReference(dest, f);
FBLOCK_UNLOCK(fb);
return f;
/* prototypes */
-Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *);
+Flow *FlowGetFlowFromHash(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *, Flow **);
void FlowDisableTcpReuseHandling(void);
{
SCLogDebug("packet %"PRIu64" -- flow %p", p->pcap_cnt, f);
- /* Point the Packet at the Flow */
- FlowReference(&p->flow, f);
-
/* update flags and counters */
if (FlowGetPacketDirection(f, p) == TOSERVER) {
f->todstpktcnt++;
/* Get this packet's flow from the hash. FlowHandlePacket() will setup
* a new flow if nescesary. If we get NULL, we're out of flow memory.
* The returned flow is locked. */
- Flow *f = FlowGetFlowFromHash(tv, dtv, p);
+ Flow *f = FlowGetFlowFromHash(tv, dtv, p, &p->flow);
if (f == NULL)
return;
void FlowHandlePacketUpdateRemove(Flow *f, Packet *p);
void FlowHandlePacketUpdate(Flow *f, Packet *p);
-Flow *FlowGetFlowFromHashByPacket(const Packet *p);
-Flow *FlowLookupFlowFromHash(const Packet *p);
+Flow *FlowGetFlowFromHashByPacket(const Packet *p, Flow **dest);
+Flow *FlowLookupFlowFromHash(const Packet *p, Flow **dest);
#endif /* __FLOW_H__ */
* a different thread. */
/* Get a flow. It will be either a locked flow or NULL */
- Flow *new_f = FlowGetFlowFromHashByPacket(p);
+ Flow *new_f = FlowGetFlowFromHashByPacket(p, &p->flow);
if (new_f == NULL) {
FlowDeReference(&old_f); // < can't disappear while usecnt >0
return;
FlowDeReference(&p->flow); // < can't disappear while usecnt >0
/* find the new flow that does belong to this packet */
- Flow *new_f = FlowLookupFlowFromHash(p);
+ Flow *new_f = FlowLookupFlowFromHash(p, &p->flow);
if (new_f == NULL) {
// TODO reset packet flag wrt flow: direction, HAS_FLOW etc
p->flags &= ~PKT_HAS_FLOW;