]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Move memset() out of PACKET_INITIALIZE()
authorKen Steele <ken@tilera.com>
Tue, 14 May 2013 19:00:21 +0000 (15:00 -0400)
committerVictor Julien <victor@inliniac.net>
Wed, 15 May 2013 10:30:16 +0000 (12:30 +0200)
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.

src/decode-ipv4.c
src/decode.c
src/decode.h
src/stream-tcp.c
src/tmqh-packetpool.c

index 6477e2f05a51211e3ca5b1cc98324b1e8f912350..5e1c0e20d66747935a4f216e64807964ca2fbe7d 100644 (file)
@@ -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);
index 99c664e1e055a7688dea902eb8e79597ad8cb785..4f1c57b4f636212a9c586e556e36a05a76f8c37e 100644 (file)
@@ -89,6 +89,7 @@ Packet *PacketGetFromAlloc(void)
         return NULL;
     }
 
+    memset(p, 0, SIZE_OF_PACKET);
     PACKET_INITIALIZE(p);
     p->flags |= PKT_ALLOC;
 
index c918e9b472da1080ab808e090ab996222652a962..446bdf6f7d25e9c029463efec06719b1e19e998f 100644 (file)
@@ -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); \
index d6033c0600286bea64642eeeb72d28cbc6e61ac1..c6334b45cdbeddb235a7043e6d94db30972f6f74 100644 (file)
@@ -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) {
index 7bd7a591536e98f43fa2c3c0f2325bd39d7e6a88..0418d03e6065258b30d51660551fcd3a442d8faa 100644 (file)
@@ -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);