diff --git a/src/flow-hash.c b/src/flow-hash.c index 34ccde0691..52bbd8ebcd 100644 --- a/src/flow-hash.c +++ b/src/flow-hash.c @@ -154,7 +154,7 @@ void FlowHashDebugDeinit(void) * detect-engine-address-ipv6.c's AddressIPv6GtU32 is likely * what you are looking for. */ -static inline int FlowHashRawAddressIPv6GtU32(uint32_t *a, uint32_t *b) +static inline int FlowHashRawAddressIPv6GtU32(const uint32_t *a, const uint32_t *b) { int i; @@ -207,7 +207,7 @@ typedef struct FlowHashKey6_ { * * For ICMP we only consider UNREACHABLE errors atm. */ -static inline uint32_t FlowGetKey(Packet *p) +static inline uint32_t FlowGetKey(const Packet *p) { uint32_t key; @@ -346,7 +346,7 @@ static inline uint32_t FlowGetKey(Packet *p) * \retval 1 match * \retval 0 no match */ -static inline int FlowCompareICMPv4(Flow *f, Packet *p) +static inline int FlowCompareICMPv4(Flow *f, const Packet *p) { if (ICMPV4_DEST_UNREACH_IS_VALID(p)) { /* first check the direction of the flow, in other words, the client -> @@ -386,7 +386,7 @@ static inline int FlowCompareICMPv4(Flow *f, Packet *p) return 0; } -static inline int FlowCompare(Flow *f, Packet *p) +static inline int FlowCompare(Flow *f, const Packet *p) { if (p->proto == IPPROTO_ICMP) { return FlowCompareICMPv4(f, p); @@ -405,7 +405,7 @@ static inline int FlowCompare(Flow *f, Packet *p) * \retval 1 true * \retval 0 false */ -static inline int FlowCreateCheck(Packet *p) +static inline int FlowCreateCheck(const Packet *p) { if (PKT_IS_ICMPV4(p)) { if (ICMPV4_IS_ERROR_MSG(p)) { @@ -424,7 +424,7 @@ static inline int FlowCreateCheck(Packet *p) * * \retval f *LOCKED* flow on succes, NULL on error. */ -static Flow *FlowGetNew(Packet *p) +static Flow *FlowGetNew(const Packet *p) { Flow *f = NULL; @@ -487,7 +487,7 @@ static Flow *FlowGetNew(Packet *p) * * returns a *LOCKED* flow or NULL */ -Flow *FlowGetFlowFromHash(Packet *p) +Flow *FlowGetFlowFromHash(const Packet *p) { Flow *f = NULL; FlowHashCountInit; @@ -515,9 +515,6 @@ Flow *FlowGetFlowFromHash(Packet *p) fb->head = f; fb->tail = f; - /* Point the Packet at the Flow */ - FlowReference(&p->flow, f); - /* got one, now lock, initialize and return */ FlowInit(f, p); f->fb = fb; @@ -553,9 +550,6 @@ Flow *FlowGetFlowFromHash(Packet *p) f->hprev = pf; - /* Point the Packet at the Flow */ - FlowReference(&p->flow, f); - /* initialize and return */ FlowInit(f, p); f->fb = fb; @@ -583,9 +577,6 @@ Flow *FlowGetFlowFromHash(Packet *p) fb->head->hprev = f; fb->head = f; - /* Point the Packet at the Flow */ - FlowReference(&p->flow, f); - /* found our flow, lock & return */ FLOWLOCK_WRLOCK(f); FBLOCK_UNLOCK(fb); @@ -595,8 +586,6 @@ Flow *FlowGetFlowFromHash(Packet *p) } } - /* Point the Packet at the Flow */ - FlowReference(&p->flow, f); /* lock & return */ FLOWLOCK_WRLOCK(f); FBLOCK_UNLOCK(fb); diff --git a/src/flow-hash.h b/src/flow-hash.h index 3279f80113..0de1a64346 100644 --- a/src/flow-hash.h +++ b/src/flow-hash.h @@ -68,7 +68,7 @@ typedef struct FlowBucket_ { /* prototypes */ -Flow *FlowGetFlowFromHash(Packet *); +Flow *FlowGetFlowFromHash(const Packet *); /** enable to print stats on hash lookups in flow-debug.log */ //#define FLOW_DEBUG_STATS diff --git a/src/flow-util.c b/src/flow-util.c index e680fabca9..f677464fdd 100644 --- a/src/flow-util.c +++ b/src/flow-util.c @@ -106,7 +106,7 @@ uint8_t FlowGetProtoMapping(uint8_t proto) /* initialize the flow from the first packet * we see from it. */ -void FlowInit(Flow *f, Packet *p) +void FlowInit(Flow *f, const Packet *p) { SCEnter(); SCLogDebug("flow %p", f); diff --git a/src/flow-util.h b/src/flow-util.h index 03cf471848..40ae8117f8 100644 --- a/src/flow-util.h +++ b/src/flow-util.h @@ -134,7 +134,7 @@ Flow *FlowAlloc(void); Flow *FlowAllocDirect(void); void FlowFree(Flow *); uint8_t FlowGetProtoMapping(uint8_t); -void FlowInit(Flow *, Packet *); +void FlowInit(Flow *, const Packet *); #endif /* __FLOW_UTIL_H__ */ diff --git a/src/flow.c b/src/flow.c index dcf49ed2ab..89b34d8ed2 100644 --- a/src/flow.c +++ b/src/flow.c @@ -177,7 +177,7 @@ void FlowSetIPOnlyFlagNoLock(Flow *f, char direction) * \retval 0 to_server * \retval 1 to_client */ -int FlowGetPacketDirection(Flow *f, Packet *p) +int FlowGetPacketDirection(Flow *f, const Packet *p) { if (p->proto == IPPROTO_TCP || p->proto == IPPROTO_UDP || p->proto == IPPROTO_SCTP) { if (!(CMP_PORT(p->sp,p->dp))) { @@ -214,7 +214,7 @@ int FlowGetPacketDirection(Flow *f, Packet *p) * \retval 1 true * \retval 0 false */ -static inline int FlowUpdateSeenFlag(Packet *p) +static inline int FlowUpdateSeenFlag(const Packet *p) { if (PKT_IS_ICMPV4(p)) { if (ICMPV4_IS_ERROR_MSG(p)) { @@ -232,7 +232,7 @@ static inline int FlowUpdateSeenFlag(Packet *p) * \param tv threadvars * \param p packet to handle flow for */ -void FlowHandlePacket (ThreadVars *tv, Packet *p) +void FlowHandlePacket(ThreadVars *tv, Packet *p) { /* 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. @@ -241,11 +241,14 @@ void FlowHandlePacket (ThreadVars *tv, Packet *p) if (f == NULL) return; + /* Point the Packet at the Flow */ + FlowReference(&p->flow, f); + /* update the last seen timestamp of this flow */ f->lastts_sec = p->ts.tv_sec; /* update flags and counters */ - if (FlowGetPacketDirection(f,p) == TOSERVER) { + if (FlowGetPacketDirection(f, p) == TOSERVER) { if (FlowUpdateSeenFlag(p)) { f->flags |= FLOW_TO_DST_SEEN; } diff --git a/src/flow.h b/src/flow.h index 843e10790f..4b71316e01 100644 --- a/src/flow.h +++ b/src/flow.h @@ -412,7 +412,7 @@ static inline void FlowLockSetNoPayloadInspectionFlag(Flow *); static inline void FlowSetNoPayloadInspectionFlag(Flow *); static inline void FlowSetSessionNoApplayerInspectionFlag(Flow *); -int FlowGetPacketDirection(Flow *, Packet *); +int FlowGetPacketDirection(Flow *, const Packet *); void FlowCleanupAppLayer(Flow *);