Add const for Packet * in flow functions.

By moving FlowReference() out of FlowGetFlowFromHash() and into the one
function that calls it, all the flow functions take const Packet * instead
of Packet *.
pull/724/merge
Ken Steele 12 years ago committed by Victor Julien
parent 8ba0fa7f92
commit d12834769a

@ -154,7 +154,7 @@ void FlowHashDebugDeinit(void)
* detect-engine-address-ipv6.c's AddressIPv6GtU32 is likely * detect-engine-address-ipv6.c's AddressIPv6GtU32 is likely
* what you are looking for. * 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; int i;
@ -207,7 +207,7 @@ typedef struct FlowHashKey6_ {
* *
* For ICMP we only consider UNREACHABLE errors atm. * 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; uint32_t key;
@ -346,7 +346,7 @@ static inline uint32_t FlowGetKey(Packet *p)
* \retval 1 match * \retval 1 match
* \retval 0 no 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)) { if (ICMPV4_DEST_UNREACH_IS_VALID(p)) {
/* first check the direction of the flow, in other words, the client -> /* 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; return 0;
} }
static inline int FlowCompare(Flow *f, Packet *p) static inline int FlowCompare(Flow *f, const Packet *p)
{ {
if (p->proto == IPPROTO_ICMP) { if (p->proto == IPPROTO_ICMP) {
return FlowCompareICMPv4(f, p); return FlowCompareICMPv4(f, p);
@ -405,7 +405,7 @@ static inline int FlowCompare(Flow *f, Packet *p)
* \retval 1 true * \retval 1 true
* \retval 0 false * \retval 0 false
*/ */
static inline int FlowCreateCheck(Packet *p) static inline int FlowCreateCheck(const Packet *p)
{ {
if (PKT_IS_ICMPV4(p)) { if (PKT_IS_ICMPV4(p)) {
if (ICMPV4_IS_ERROR_MSG(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. * \retval f *LOCKED* flow on succes, NULL on error.
*/ */
static Flow *FlowGetNew(Packet *p) static Flow *FlowGetNew(const Packet *p)
{ {
Flow *f = NULL; Flow *f = NULL;
@ -487,7 +487,7 @@ static Flow *FlowGetNew(Packet *p)
* *
* returns a *LOCKED* flow or NULL * returns a *LOCKED* flow or NULL
*/ */
Flow *FlowGetFlowFromHash(Packet *p) Flow *FlowGetFlowFromHash(const Packet *p)
{ {
Flow *f = NULL; Flow *f = NULL;
FlowHashCountInit; FlowHashCountInit;
@ -515,9 +515,6 @@ Flow *FlowGetFlowFromHash(Packet *p)
fb->head = f; fb->head = f;
fb->tail = f; fb->tail = f;
/* Point the Packet at the Flow */
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;
@ -553,9 +550,6 @@ Flow *FlowGetFlowFromHash(Packet *p)
f->hprev = pf; f->hprev = pf;
/* Point the Packet at the Flow */
FlowReference(&p->flow, f);
/* initialize and return */ /* initialize and return */
FlowInit(f, p); FlowInit(f, p);
f->fb = fb; f->fb = fb;
@ -583,9 +577,6 @@ Flow *FlowGetFlowFromHash(Packet *p)
fb->head->hprev = f; fb->head->hprev = f;
fb->head = f; fb->head = f;
/* Point the Packet at the Flow */
FlowReference(&p->flow, f);
/* found our flow, lock & return */ /* found our flow, lock & return */
FLOWLOCK_WRLOCK(f); FLOWLOCK_WRLOCK(f);
FBLOCK_UNLOCK(fb); FBLOCK_UNLOCK(fb);
@ -595,8 +586,6 @@ Flow *FlowGetFlowFromHash(Packet *p)
} }
} }
/* Point the Packet at the Flow */
FlowReference(&p->flow, f);
/* lock & return */ /* lock & return */
FLOWLOCK_WRLOCK(f); FLOWLOCK_WRLOCK(f);
FBLOCK_UNLOCK(fb); FBLOCK_UNLOCK(fb);

@ -68,7 +68,7 @@ typedef struct FlowBucket_ {
/* prototypes */ /* prototypes */
Flow *FlowGetFlowFromHash(Packet *); Flow *FlowGetFlowFromHash(const Packet *);
/** enable to print stats on hash lookups in flow-debug.log */ /** enable to print stats on hash lookups in flow-debug.log */
//#define FLOW_DEBUG_STATS //#define FLOW_DEBUG_STATS

@ -106,7 +106,7 @@ uint8_t FlowGetProtoMapping(uint8_t proto)
/* initialize the flow from the first packet /* initialize the flow from the first packet
* we see from it. */ * we see from it. */
void FlowInit(Flow *f, Packet *p) void FlowInit(Flow *f, const Packet *p)
{ {
SCEnter(); SCEnter();
SCLogDebug("flow %p", f); SCLogDebug("flow %p", f);

@ -134,7 +134,7 @@ Flow *FlowAlloc(void);
Flow *FlowAllocDirect(void); Flow *FlowAllocDirect(void);
void FlowFree(Flow *); void FlowFree(Flow *);
uint8_t FlowGetProtoMapping(uint8_t); uint8_t FlowGetProtoMapping(uint8_t);
void FlowInit(Flow *, Packet *); void FlowInit(Flow *, const Packet *);
#endif /* __FLOW_UTIL_H__ */ #endif /* __FLOW_UTIL_H__ */

@ -177,7 +177,7 @@ void FlowSetIPOnlyFlagNoLock(Flow *f, char direction)
* \retval 0 to_server * \retval 0 to_server
* \retval 1 to_client * \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 (p->proto == IPPROTO_TCP || p->proto == IPPROTO_UDP || p->proto == IPPROTO_SCTP) {
if (!(CMP_PORT(p->sp,p->dp))) { if (!(CMP_PORT(p->sp,p->dp))) {
@ -214,7 +214,7 @@ int FlowGetPacketDirection(Flow *f, Packet *p)
* \retval 1 true * \retval 1 true
* \retval 0 false * \retval 0 false
*/ */
static inline int FlowUpdateSeenFlag(Packet *p) static inline int FlowUpdateSeenFlag(const Packet *p)
{ {
if (PKT_IS_ICMPV4(p)) { if (PKT_IS_ICMPV4(p)) {
if (ICMPV4_IS_ERROR_MSG(p)) { if (ICMPV4_IS_ERROR_MSG(p)) {
@ -232,7 +232,7 @@ static inline int FlowUpdateSeenFlag(Packet *p)
* \param tv threadvars * \param tv threadvars
* \param p packet to handle flow for * \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 /* 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. * 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) if (f == NULL)
return; return;
/* Point the Packet at the Flow */
FlowReference(&p->flow, f);
/* update the last seen timestamp of this flow */ /* update the last seen timestamp of this flow */
f->lastts_sec = p->ts.tv_sec; f->lastts_sec = p->ts.tv_sec;
/* update flags and counters */ /* update flags and counters */
if (FlowGetPacketDirection(f,p) == TOSERVER) { if (FlowGetPacketDirection(f, p) == TOSERVER) {
if (FlowUpdateSeenFlag(p)) { if (FlowUpdateSeenFlag(p)) {
f->flags |= FLOW_TO_DST_SEEN; f->flags |= FLOW_TO_DST_SEEN;
} }

@ -412,7 +412,7 @@ static inline void FlowLockSetNoPayloadInspectionFlag(Flow *);
static inline void FlowSetNoPayloadInspectionFlag(Flow *); static inline void FlowSetNoPayloadInspectionFlag(Flow *);
static inline void FlowSetSessionNoApplayerInspectionFlag(Flow *); static inline void FlowSetSessionNoApplayerInspectionFlag(Flow *);
int FlowGetPacketDirection(Flow *, Packet *); int FlowGetPacketDirection(Flow *, const Packet *);
void FlowCleanupAppLayer(Flow *); void FlowCleanupAppLayer(Flow *);

Loading…
Cancel
Save