From: Victor Julien Date: Wed, 9 Jul 2014 06:50:26 +0000 (+0200) Subject: packet recycle: split macro X-Git-Tag: suricata-2.1beta2~178 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=231b993f1f91151f814d05fada3d16815625e9cf;p=thirdparty%2Fsuricata.git packet recycle: split macro 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. --- diff --git a/src/decode.c b/src/decode.c index a7eeccd889..7baef99744 100644 --- a/src/decode.c +++ b/src/decode.c @@ -103,7 +103,7 @@ static inline void PacketFreeExtData(Packet *p) */ void PacketFree(Packet *p) { - PACKET_CLEANUP(p); + PACKET_DESTRUCTOR(p); SCFree(p); } diff --git a/src/decode.h b/src/decode.h index d99d3d4bea..f36fdded23 100644 --- a/src/decode.h +++ b/src/decode.h @@ -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); \ } \ diff --git a/src/stream-tcp.c b/src/stream-tcp.c index d76496a926..8bc4972b8c 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -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; } diff --git a/src/tmqh-packetpool.c b/src/tmqh-packetpool.c index 16b0abe725..9b84f55b45 100644 --- a/src/tmqh-packetpool.c +++ b/src/tmqh-packetpool.c @@ -293,8 +293,7 @@ void PacketPoolDestroy(void) { Packet *p = NULL; while ((p = PacketPoolGetPacket()) != NULL) { - PACKET_CLEANUP(p); - SCFree(p); + PacketFree(p); } }