]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
packet pool: fix ext_pkt cleaning
authorEric Leblond <eric@regit.org>
Wed, 13 Aug 2014 08:48:26 +0000 (10:48 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 13 Aug 2014 13:57:08 +0000 (15:57 +0200)
The field ext_pkt was cleaned before calling the release function.
The result was that IPS mode such as the one of AF_PACKET were not
working anymore because they were not able to send the data which
were initially pointed by ext_pkt.

This patch moves the ext_pkt cleaning to the cleaning macro. This
ensures that the cleaning is done for allocated and pool packets.

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

index 7baef99744fe1e1abe82355f0c8c8d15d5579413..150d1cb02ad7f8f75b5fd0b464a550b942c6c0a5 100644 (file)
@@ -85,7 +85,7 @@ int DecodeTunnel(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p,
     return TM_ECODE_OK;
 }
 
-static inline void PacketFreeExtData(Packet *p)
+void PacketFreeExtData(Packet *p)
 {
     /* if p uses extended data, free them */
     if (p->ext_pkt) {
@@ -96,8 +96,6 @@ static inline void PacketFreeExtData(Packet *p)
     }
 }
 
-
-
 /**
  * \brief Return a malloced packet.
  */
@@ -156,7 +154,6 @@ Packet *PacketGetFromAlloc(void)
  */
 void PacketFreeOrRelease(Packet *p)
 {
-    PacketFreeExtData(p);
     if (p->flags & PKT_ALLOC)
         PacketFree(p);
     else
index 4f83a8be79084b66763b62e84d0ba76530d8750a..69f72da213bd9b2b2f4f8a66b8f5148ee88a69b7 100644 (file)
@@ -623,6 +623,8 @@ typedef struct DecodeThreadVars_
         (p)->level4_comp_csum = -1;   \
     } while (0)
 
+void PacketFreeExtData(Packet *p);
+
 /**
  *  \brief Initialize a packet structure for use.
  */
@@ -662,6 +664,7 @@ typedef struct DecodeThreadVars_
         (p)->dp = 0;                            \
         (p)->proto = 0;                         \
         (p)->recursion_level = 0;               \
+        PacketFreeExtData(p);                   \
         (p)->flags = (p)->flags & PKT_ALLOC;    \
         (p)->flowflags = 0;                     \
         (p)->pkt_src = 0;                       \
@@ -733,6 +736,7 @@ typedef struct DecodeThreadVars_
         if ((p)->pktvar != NULL) {              \
             PktVarFree((p)->pktvar);            \
         }                                       \
+        PacketFreeExtData(p);                   \
         SCMutexDestroy(&(p)->tunnel_mutex);     \
         AppLayerDecoderEventsFreeEvents(&(p)->app_layer_events); \
         PACKET_PROFILING_RESET((p));            \
index b26d6b09d9afe9121cad667b70ee5dab478340a8..38ca297c7054690a40261f0b72ad48ccb3dd43b8 100644 (file)
@@ -396,25 +396,11 @@ void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
         SCLogDebug("getting rid of root pkt... alloc'd %s", p->root->flags & PKT_ALLOC ? "true" : "false");
 
         FlowDeReference(&p->root->flow);
-        /* if p->root uses extended data, free them */
-        if (p->root->ext_pkt) {
-            if (!(p->root->flags & PKT_ZERO_COPY)) {
-                SCFree(p->root->ext_pkt);
-            }
-            p->root->ext_pkt = NULL;
-        }
+
         p->root->ReleasePacket(p->root);
         p->root = NULL;
     }
 
-    /* if p uses extended data, free them */
-    if (p->ext_pkt) {
-        if (!(p->flags & PKT_ZERO_COPY)) {
-            SCFree(p->ext_pkt);
-        }
-        p->ext_pkt = NULL;
-    }
-
     PACKET_PROFILING_END(p);
 
     p->ReleasePacket(p);