From: Ken Steele Date: Tue, 14 May 2013 19:00:21 +0000 (-0400) Subject: Move memset() out of PACKET_INITIALIZE() X-Git-Tag: suricata-2.0beta1~146 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=699d9e01f12f4a6e88af2e61a36bb9bf46c4ee9a;p=thirdparty%2Fsuricata.git Move memset() out of PACKET_INITIALIZE() The memset() inside PACKET_INITIALIZE() is redundant in some cases and it is cleaner to do as part of the memory allocation. This simplifies changes for integrating Tilera mPIPE support because the size of memory cleared in that case is different from SIZE_OF_PACKET. For the cases where Packets are directly allocated and then call PACKET_INITIALIZE() without memset() first, this patch adds memset() calls. A further change would use GetPacketFromAlloc() directly. --- diff --git a/src/decode-ipv4.c b/src/decode-ipv4.c index 6477e2f05a..5e1c0e20d6 100644 --- a/src/decode-ipv4.c +++ b/src/decode-ipv4.c @@ -1557,6 +1557,7 @@ int DecodeIPV4DefragTest01(void) memset(&tv, 0, sizeof(ThreadVars)); memset(&dtv, 0, sizeof(DecodeThreadVars)); memset(&pq, 0, sizeof(PacketQueue)); + memset(p, 0, SIZE_OF_PACKET); PACKET_INITIALIZE(p); FlowInitConfig(FLOW_QUIET); @@ -1695,6 +1696,7 @@ int DecodeIPV4DefragTest02(void) memset(&tv, 0, sizeof(ThreadVars)); memset(&dtv, 0, sizeof(DecodeThreadVars)); memset(&pq, 0, sizeof(PacketQueue)); + memset(p, 0, SIZE_OF_PACKET); PACKET_INITIALIZE(p); FlowInitConfig(FLOW_QUIET); @@ -1824,6 +1826,7 @@ int DecodeIPV4DefragTest03(void) memset(&tv, 0, sizeof(ThreadVars)); memset(&dtv, 0, sizeof(DecodeThreadVars)); memset(&pq, 0, sizeof(PacketQueue)); + memset(p, 0, SIZE_OF_PACKET); PACKET_INITIALIZE(p); FlowInitConfig(FLOW_QUIET); diff --git a/src/decode.c b/src/decode.c index 99c664e1e0..4f1c57b4f6 100644 --- a/src/decode.c +++ b/src/decode.c @@ -89,6 +89,7 @@ Packet *PacketGetFromAlloc(void) return NULL; } + memset(p, 0, SIZE_OF_PACKET); PACKET_INITIALIZE(p); p->flags |= PKT_ALLOC; diff --git a/src/decode.h b/src/decode.h index c918e9b472..446bdf6f7d 100644 --- a/src/decode.h +++ b/src/decode.h @@ -612,7 +612,6 @@ typedef struct DecodeThreadVars_ */ #ifndef __SC_CUDA_SUPPORT__ #define PACKET_INITIALIZE(p) { \ - memset((p), 0x00, SIZE_OF_PACKET); \ SCMutexInit(&(p)->tunnel_mutex, NULL); \ PACKET_RESET_CHECKSUMS((p)); \ (p)->pkt = ((uint8_t *)(p)) + sizeof(Packet); \ @@ -620,7 +619,6 @@ typedef struct DecodeThreadVars_ } #else #define PACKET_INITIALIZE(p) { \ - memset((p), 0x00, SIZE_OF_PACKET); \ SCMutexInit(&(p)->tunnel_mutex, NULL); \ PACKET_RESET_CHECKSUMS((p)); \ SCMutexInit(&(p)->cuda_mutex, NULL); \ diff --git a/src/stream-tcp.c b/src/stream-tcp.c index d6033c0600..c6334b45cd 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -9291,6 +9291,7 @@ static int StreamTcpTest40(void) { DecodeThreadVars dtv; memset(&tv, 0, sizeof(ThreadVars)); + memset(p, 0, SIZE_OF_PACKET); PACKET_INITIALIZE(p); SET_PKT_LEN(p, sizeof(raw_vlan)); @@ -9350,6 +9351,7 @@ static int StreamTcpTest41(void) { memset(&dtv, 0, sizeof(DecodeThreadVars)); memset(&tv, 0, sizeof(ThreadVars)); + memset(p, 0, SIZE_OF_PACKET); PACKET_INITIALIZE(p); if (PacketCopyData(p, raw_ip, sizeof(raw_ip)) == -1) { diff --git a/src/tmqh-packetpool.c b/src/tmqh-packetpool.c index 7bd7a59153..0418d03e60 100644 --- a/src/tmqh-packetpool.c +++ b/src/tmqh-packetpool.c @@ -122,6 +122,7 @@ void PacketPoolInit(intmax_t max_pending_packets) { SCLogError(SC_ERR_FATAL, "Fatal error encountered while allocating a packet. Exiting..."); exit(EXIT_FAILURE); } + memset(p, 0, SIZE_OF_PACKET); PACKET_INITIALIZE(p); PacketPoolStorePacket(p);