From: Eric Leblond Date: Wed, 13 Aug 2014 08:48:26 +0000 (+0200) Subject: packet pool: fix ext_pkt cleaning X-Git-Tag: suricata-2.1beta2~175 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=80adc40f6850a9dfcb3e43e5b1a1930c5059fbe8;p=thirdparty%2Fsuricata.git packet pool: fix ext_pkt cleaning 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. --- diff --git a/src/decode.c b/src/decode.c index 7baef99744..150d1cb02a 100644 --- a/src/decode.c +++ b/src/decode.c @@ -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 diff --git a/src/decode.h b/src/decode.h index 4f83a8be79..69f72da213 100644 --- a/src/decode.h +++ b/src/decode.h @@ -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)); \ diff --git a/src/tmqh-packetpool.c b/src/tmqh-packetpool.c index b26d6b09d9..38ca297c70 100644 --- a/src/tmqh-packetpool.c +++ b/src/tmqh-packetpool.c @@ -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);