]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Add const for Packet * in flow functions.
authorKen Steele <ken@tilera.com>
Sat, 16 Nov 2013 16:13:42 +0000 (11:13 -0500)
committerVictor Julien <victor@inliniac.net>
Fri, 13 Dec 2013 12:48:13 +0000 (13:48 +0100)
By moving FlowReference() out of FlowGetFlowFromHash() and into the one
function that calls it, all the flow functions take const Packet * instead
of Packet *.

src/flow-hash.c
src/flow-hash.h
src/flow-util.c
src/flow-util.h
src/flow.c
src/flow.h

index 34ccde0691005bf1035ed2523a1aa34f385be420..52bbd8ebcd1485eae090508e92b0345cbc3797d8 100644 (file)
@@ -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);
index 3279f80113d7e1afb0220c83679ddcb360c530db..0de1a64346902d6954cd74d0f96258e2058cd7af 100644 (file)
@@ -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
index e680fabca93a586531b3e8dd19f811b2dd31ad49..f677464fddf840be0bf06579c890606ca6150c74 100644 (file)
@@ -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);
index 03cf4718483aa401bd760d779dd049ed61ca2344..40ae8117f8af7241f3e63125ce146562a52e1deb 100644 (file)
@@ -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__ */
 
index dcf49ed2aba0c1b3112b94771e60eb4e47afab9e..89b34d8ed220190856f945ae364bfdf393b57e62 100644 (file)
@@ -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;
         }
index 843e10790ffc851d30ed0e7cd61fbdfbd645b40c..4b71316e014fc56ed94731107c524920c337e5aa 100644 (file)
@@ -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 *);