]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
packet recycle: split macro
authorVictor Julien <victor@inliniac.net>
Wed, 9 Jul 2014 06:50:26 +0000 (08:50 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 13 Aug 2014 08:43:57 +0000 (10:43 +0200)
Split PACKET_RECYCLE into 2 parts. One part for cleanup to do before a
packet is returned to the pool, the other after it's retrieved from
the pool.

src/decode.c
src/decode.h
src/stream-tcp.c
src/tmqh-packetpool.c

index a7eeccd889ed8481372c3e77e346086002f88f5b..7baef99744fe1e1abe82355f0c8c8d15d5579413 100644 (file)
@@ -103,7 +103,7 @@ static inline void PacketFreeExtData(Packet *p)
  */
 void PacketFree(Packet *p)
 {
-    PACKET_CLEANUP(p);
+    PACKET_DESTRUCTOR(p);
     SCFree(p);
 }
 
index d99d3d4bea472d28137b803e424ce174a3f77749..f36fdded23e607351e13eeaa7067604a8aa2f5b7 100644 (file)
@@ -646,11 +646,17 @@ typedef struct DecodeThreadVars_
 }
 #endif
 
+#define PACKET_RELEASE_REFS(p) do {              \
+        FlowDeReference(&((p)->flow));          \
+        HostDeReference(&((p)->host_src));      \
+        HostDeReference(&((p)->host_dst));      \
+    } while (0)
+
 /**
  *  \brief Recycle a packet structure for reuse.
  *  \todo the mutex destroy & init is necessary because of the memset, reconsider
  */
-#define PACKET_DO_RECYCLE(p) do {               \
+#define PACKET_REINIT(p) do {             \
         CLEAR_ADDR(&(p)->src);                  \
         CLEAR_ADDR(&(p)->dst);                  \
         (p)->sp = 0;                            \
@@ -663,7 +669,6 @@ typedef struct DecodeThreadVars_
         (p)->vlan_id[0] = 0;                    \
         (p)->vlan_id[1] = 0;                    \
         (p)->vlan_idx = 0;                      \
-        FlowDeReference(&((p)->flow));          \
         (p)->ts.tv_sec = 0;                     \
         (p)->ts.tv_usec = 0;                    \
         (p)->datalink = 0;                      \
@@ -704,8 +709,6 @@ typedef struct DecodeThreadVars_
         (p)->payload_len = 0;                   \
         (p)->pktlen = 0;                        \
         (p)->alerts.cnt = 0;                    \
-        HostDeReference(&((p)->host_src));      \
-        HostDeReference(&((p)->host_dst));      \
         (p)->pcap_cnt = 0;                      \
         (p)->tunnel_rtv_cnt = 0;                \
         (p)->tunnel_tpr_cnt = 0;                \
@@ -721,12 +724,15 @@ typedef struct DecodeThreadVars_
         PACKET_PROFILING_RESET((p));            \
     } while (0)
 
-#define PACKET_RECYCLE(p) PACKET_DO_RECYCLE((p))
+#define PACKET_RECYCLE(p) do { \
+        PACKET_RELEASE_REFS((p)); \
+        PACKET_REINIT((p)); \
+    } while (0)
 
 /**
  *  \brief Cleanup a packet so that we can free it. No memset needed..
  */
-#define PACKET_CLEANUP(p) do {                  \
+#define PACKET_DESTRUCTOR(p) do {                  \
         if ((p)->pktvar != NULL) {              \
             PktVarFree((p)->pktvar);            \
         }                                       \
index d76496a926674104f7697c9f865cfb574245ff87..8bc4972b8cb95c8c419b902dc53f4fa95cd60c82 100644 (file)
@@ -9785,8 +9785,7 @@ static int StreamTcpTest41(void)
     PACKET_INITIALIZE(p);
 
     if (PacketCopyData(p, raw_ip, sizeof(raw_ip)) == -1) {
-        PACKET_CLEANUP(p);
-        SCFree(p);
+        PacketFree(p);
         return 1;
     }
 
index 16b0abe725b7ec9ccfacec2e8d19ecad1f8c40f8..9b84f55b4550dde4887ff4b44148e063ed6a105b 100644 (file)
@@ -293,8 +293,7 @@ void PacketPoolDestroy(void)
 {
     Packet *p = NULL;
     while ((p = PacketPoolGetPacket()) != NULL) {
-        PACKET_CLEANUP(p);
-        SCFree(p);
+        PacketFree(p);
     }
 }