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.
pull/1104/head
Victor Julien 12 years ago
parent 04a0672f7a
commit 231b993f1f

@ -103,7 +103,7 @@ static inline void PacketFreeExtData(Packet *p)
*/
void PacketFree(Packet *p)
{
PACKET_CLEANUP(p);
PACKET_DESTRUCTOR(p);
SCFree(p);
}

@ -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); \
} \

@ -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;
}

@ -293,8 +293,7 @@ void PacketPoolDestroy(void)
{
Packet *p = NULL;
while ((p = PacketPoolGetPacket()) != NULL) {
PACKET_CLEANUP(p);
SCFree(p);
PacketFree(p);
}
}

Loading…
Cancel
Save