[Oisf-devel] [PATCH 2/2] Modify files to avoid direct pckt payload access

Eric Leblond eleblond at edenwall.com
Sat Nov 20 17:57:43 UTC 2010


This patch implements the needed modification of payload access
in a Packet structure to support the abstraction introduced by
the extended data system.

Signed-off-by: Eric Leblond <eleblond at edenwall.com>
---
 src/alert-debuglog.c         |   12 ++--
 src/alert-fastlog.c          |    2 +-
 src/alert-unified-log.c      |    8 +-
 src/alert-unified2-alert.c   |   20 +++---
 src/app-layer-detect-proto.c |    4 +-
 src/cuda-packet-batcher.c    |    4 +-
 src/decode-ethernet.c        |    2 +-
 src/decode-gre.c             |   14 ++--
 src/decode-icmpv4.c          |   12 ++--
 src/decode-icmpv6.c          |   26 +++---
 src/decode-ipv4.c            |   66 ++++++++--------
 src/decode-ipv6.c            |    2 +-
 src/decode-ppp.c             |    8 +-
 src/decode-pppoe.c           |   10 +-
 src/decode-raw.c             |   22 +++---
 src/decode-tcp.c             |    6 +-
 src/decode-vlan.c            |    6 +-
 src/defrag.c                 |  167 ++++++++++++++++++++++++-----------------
 src/detect-bytetest.c        |    6 +-
 src/detect-content.c         |    2 +-
 src/detect-decode-event.c    |    2 +-
 src/detect-dsize.c           |    2 +-
 src/detect-engine-tag.c      |    6 +-
 src/detect-flags.c           |   20 +++---
 src/detect-flowbits.c        |    6 +-
 src/detect-flowint.c         |    6 +-
 src/detect-fragbits.c        |    4 +-
 src/detect-fragoffset.c      |    2 +-
 src/detect-icmp-id.c         |    2 +-
 src/detect-ipopts.c          |    4 +-
 src/detect-stream_size.c     |    4 +-
 src/detect.c                 |  104 ++++++++++++++------------
 src/flow.c                   |    2 +-
 src/source-erf-dag.c         |   21 +++---
 src/source-erf-file.c        |   16 ++--
 src/source-ipfw.c            |   28 ++++----
 src/source-nfq.c             |   29 ++++---
 src/source-pcap-file.c       |   18 ++--
 src/source-pcap.c            |   26 ++++---
 src/source-pfring.c          |   16 ++--
 src/stream-tcp.c             |   64 ++++++++--------
 src/suricata.c               |    6 +-
 src/util-mpm-b2g-cuda.c      |   10 +-
 src/util-unittest-helper.c   |   25 +++---
 44 files changed, 433 insertions(+), 389 deletions(-)

diff --git a/src/alert-debuglog.c b/src/alert-debuglog.c
index 76db5d9..e7a04d4 100644
--- a/src/alert-debuglog.c
+++ b/src/alert-debuglog.c
@@ -248,9 +248,9 @@ TmEcode AlertDebugLogIPv4(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq
 
     aft->file_ctx->alerts += p->alerts.cnt;
 
-    fprintf(aft->file_ctx->fp, "PACKET LEN:        %" PRIu32 "\n", p->pktlen);
+    fprintf(aft->file_ctx->fp, "PACKET LEN:        %" PRIu32 "\n", GET_PKT_LEN(p));
     fprintf(aft->file_ctx->fp, "PACKET:\n");
-    PrintRawDataFp(aft->file_ctx->fp, p->pkt, p->pktlen);
+    PrintRawDataFp(aft->file_ctx->fp, GET_PKT_DATA(p), GET_PKT_LEN(p));
 
     fflush(aft->file_ctx->fp);
     SCMutexUnlock(&aft->file_ctx->fp_mutex);
@@ -313,9 +313,9 @@ TmEcode AlertDebugLogIPv6(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq
 
     AlertDebugLogPktVars(aft, p);
 
-    fprintf(aft->file_ctx->fp, "PACKET LEN:        %" PRIu32 "\n", p->pktlen);
+    fprintf(aft->file_ctx->fp, "PACKET LEN:        %" PRIu32 "\n", GET_PKT_LEN(p));
     fprintf(aft->file_ctx->fp, "PACKET:\n");
-    PrintRawDataFp(aft->file_ctx->fp, p->pkt, p->pktlen);
+    PrintRawDataFp(aft->file_ctx->fp, GET_PKT_DATA(p), GET_PKT_LEN(p));
 
     fflush(aft->file_ctx->fp);
     SCMutexUnlock(&aft->file_ctx->fp_mutex);
@@ -356,9 +356,9 @@ TmEcode AlertDebugLogDecoderEvent(ThreadVars *tv, Packet *p, void *data, PacketQ
 
     aft->file_ctx->alerts += p->alerts.cnt;
 
-    fprintf(aft->file_ctx->fp, "PACKET LEN:        %" PRIu32 "\n", p->pktlen);
+    fprintf(aft->file_ctx->fp, "PACKET LEN:        %" PRIu32 "\n", GET_PKT_LEN(p));
     fprintf(aft->file_ctx->fp, "PACKET:\n");
-    PrintRawDataFp(aft->file_ctx->fp, p->pkt, p->pktlen);
+    PrintRawDataFp(aft->file_ctx->fp, GET_PKT_DATA(p), GET_PKT_LEN(p));
 
     fflush(aft->file_ctx->fp);
     SCMutexUnlock(&aft->file_ctx->fp_mutex);
diff --git a/src/alert-fastlog.c b/src/alert-fastlog.c
index 1131a3f..3ca91cc 100644
--- a/src/alert-fastlog.c
+++ b/src/alert-fastlog.c
@@ -235,7 +235,7 @@ TmEcode AlertFastLogDecoderEvent(ThreadVars *tv, Packet *p, void *data, PacketQu
         fprintf(aft->file_ctx->fp, "%s  [**] [%" PRIu32 ":%" PRIu32 ":%" PRIu32 "] %s [**] [Classification: %s] [Priority: %" PRIu32 "] [**] [Raw pkt: ",
                 timebuf, pa->gid, pa->sid, pa->rev, pa->msg, pa->class_msg, pa->prio);
 
-        PrintRawLineHexFp(aft->file_ctx->fp, p->pkt, p->pktlen < 32 ? p->pktlen : 32);
+        PrintRawLineHexFp(aft->file_ctx->fp, GET_PKT_DATA(p), GET_PKT_LEN(p) < 32 ? GET_PKT_LEN(p) : 32);
         if (p->pcap_cnt != 0) {
             fprintf(aft->file_ctx->fp, "] [pcap file packet: %"PRIu64"]", p->pcap_cnt);
         }
diff --git a/src/alert-unified-log.c b/src/alert-unified-log.c
index 2ee5903..8901323 100644
--- a/src/alert-unified-log.c
+++ b/src/alert-unified-log.c
@@ -212,7 +212,7 @@ TmEcode AlertUnifiedLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq,
     hdr.tv.tv_sec = hdr.ref_tv.tv_sec = p->ts.tv_sec;
     hdr.tv.tv_usec = hdr.ref_tv.tv_usec = p->ts.tv_usec;
     hdr.pktflags = 0; /* XXX */
-    hdr.pktlen = hdr.caplen = p->pktlen + ethh_offset;
+    hdr.pktlen = hdr.caplen = GET_PKT_LEN(p) + ethh_offset;
 
 
     uint16_t i = 0;
@@ -244,13 +244,13 @@ TmEcode AlertUnifiedLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq,
             buflen += sizeof(ethh);
         }
 
-        memcpy(buf+buflen,&p->pkt,p->pktlen);
-        buflen += p->pktlen;
+        memcpy(buf+buflen, GET_PKT_DATA(p),GET_PKT_LEN(p));
+        buflen += GET_PKT_LEN(p);
 
         /** Wait for the mutex. We dont want all the threads rotating the file
          * at the same time :) */
         SCMutexLock(&aun->file_ctx->fp_mutex);
-        if ((aun->file_ctx->size_current + sizeof(hdr) + p->pktlen + ethh_offset) > aun->file_ctx->size_limit) {
+        if ((aun->file_ctx->size_current + sizeof(hdr) + GET_PKT_LEN(p) + ethh_offset) > aun->file_ctx->size_limit) {
             if (AlertUnifiedLogRotateFile(tv,aun) < 0) {
                 SCMutexUnlock(&aun->file_ctx->fp_mutex);
                 aun->file_ctx->alerts += i;
diff --git a/src/alert-unified2-alert.c b/src/alert-unified2-alert.c
index 7ea721d..f0cd086 100644
--- a/src/alert-unified2-alert.c
+++ b/src/alert-unified2-alert.c
@@ -240,8 +240,8 @@ int Unified2PacketTypeAlert (ThreadVars *t, Packet *p, void *data)
     int ret, len;
     char write_buffer[sizeof(Unified2AlertFileHeader) + sizeof(Unified2Packet) + IPV4_MAXPACKET_LEN];
 
-    if(p->pktlen > 0)
-        len = (sizeof(Unified2AlertFileHeader) + sizeof(Unified2Packet)) - 4 + p->pktlen;
+    if(GET_PKT_LEN(p) > 0)
+        len = (sizeof(Unified2AlertFileHeader) + sizeof(Unified2Packet)) - 4 + GET_PKT_LEN(p);
     else
         len = (sizeof(Unified2AlertFileHeader) + sizeof(Unified2Packet)) - 4;
 
@@ -251,7 +251,7 @@ int Unified2PacketTypeAlert (ThreadVars *t, Packet *p, void *data)
     memset(&phdr, 0, sizeof(Unified2Packet));
 
     hdr.type = htonl(UNIFIED2_PACKET_TYPE);
-    hdr.length = htonl(sizeof(Unified2Packet) -4 + p->pktlen);
+    hdr.length = htonl(sizeof(Unified2Packet) -4 + GET_PKT_LEN(p));
 
     memcpy(write_buffer,&hdr,sizeof(Unified2AlertFileHeader));
 
@@ -260,10 +260,10 @@ int Unified2PacketTypeAlert (ThreadVars *t, Packet *p, void *data)
     phdr.event_id = 0;
     phdr.event_second = phdr.packet_second = htonl(p->ts.tv_sec);
     phdr.packet_microsecond = htonl(p->ts.tv_usec);
-    phdr.packet_length = htonl(p->pktlen);
+    phdr.packet_length = htonl(GET_PKT_LEN(p));
 
     memcpy(write_buffer+sizeof(Unified2AlertFileHeader),&phdr,sizeof(Unified2Packet) - 4);
-    memcpy(write_buffer + sizeof(Unified2AlertFileHeader) + sizeof(Unified2Packet) - 4 , p->pkt, p->pktlen);
+    memcpy(write_buffer + sizeof(Unified2AlertFileHeader) + sizeof(Unified2Packet) - 4 , GET_PKT_DATA(p), GET_PKT_LEN(p));
 
     ret = fwrite(write_buffer,len, 1, aun->file_ctx->fp);
     if (ret != 1) {
@@ -762,7 +762,7 @@ static int Unified2Test01 (void)   {
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&tv, 0, sizeof(ThreadVars));
     memset(&pq, 0, sizeof(PacketQueue));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     p.alerts.cnt++;
     p.alerts.alerts[p.alerts.cnt-1].sid = 1;
@@ -831,7 +831,7 @@ static int Unified2Test02 (void)   {
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&tv, 0, sizeof(ThreadVars));
     memset(&pq, 0, sizeof(PacketQueue));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     p.alerts.cnt++;
     p.alerts.alerts[p.alerts.cnt-1].sid = 1;
@@ -906,7 +906,7 @@ static int Unified2Test03 (void) {
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&tv, 0, sizeof(ThreadVars));
     memset(&pq, 0, sizeof(PacketQueue));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     p.alerts.cnt++;
     p.alerts.alerts[p.alerts.cnt-1].sid = 1;
@@ -975,7 +975,7 @@ static int Unified2Test04 (void)   {
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&tv, 0, sizeof(ThreadVars));
     memset(&pq, 0, sizeof(PacketQueue));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     p.alerts.cnt++;
     p.alerts.alerts[p.alerts.cnt-1].sid = 1;
@@ -1042,7 +1042,7 @@ static int Unified2Test05 (void)   {
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&tv, 0, sizeof(ThreadVars));
     memset(&pq, 0, sizeof(PacketQueue));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     p.alerts.cnt++;
     p.alerts.alerts[p.alerts.cnt-1].sid = 1;
diff --git a/src/app-layer-detect-proto.c b/src/app-layer-detect-proto.c
index 7bd071a..6df2dea 100644
--- a/src/app-layer-detect-proto.c
+++ b/src/app-layer-detect-proto.c
@@ -474,10 +474,10 @@ uint16_t AppLayerDetectGetProto(AlpProtoDetectCtx *ctx, AlpProtoDetectThreadCtx
                                                 &tdir->pmq, buf,
                                                 searchlen);
 #else
-    Packet *p = SCMalloc(sizeof(Packet));
+    Packet *p = SCMalloc(SIZE_OF_PACKET);
     if (p == NULL)
         goto end;
-    memset(p, 0, sizeof(Packet));
+    memset(p, 0, SIZE_OF_PACKET);
 
     p->cuda_done = 0;
     p->cuda_free_packet = 1;
diff --git a/src/cuda-packet-batcher.c b/src/cuda-packet-batcher.c
index 6ce9cf3..1f8681d 100644
--- a/src/cuda-packet-batcher.c
+++ b/src/cuda-packet-batcher.c
@@ -980,7 +980,7 @@ int SCCudaPBTest01(void)
     packets_buffer_len += packets_offset_buffer[(sizeof(strings)/sizeof(char *)) - 1] +
         sizeof(SCCudaPBPacketDataForGPUNonPayload) + strlen(strings[(sizeof(strings)/sizeof(char *)) - 1]);
 
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&tv, 0, sizeof(ThreadVars));
     memset(&tv_cuda_PB, 0, sizeof(ThreadVars));
@@ -1208,7 +1208,7 @@ int SCCudaPBTest02(void)
     SCDQDataQueue *dq = NULL;
 
 
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&tv, 0, sizeof(ThreadVars));
     memset(&tv_cuda_PB, 0, sizeof(ThreadVars));
diff --git a/src/decode-ethernet.c b/src/decode-ethernet.c
index b5ab541..cd5778f 100644
--- a/src/decode-ethernet.c
+++ b/src/decode-ethernet.c
@@ -111,7 +111,7 @@ static int DecodeEthernetTest01 (void)   {
 
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&tv,  0, sizeof(ThreadVars));
-    memset(&p,   0, sizeof(Packet));
+    memset(&p,   0, SIZE_OF_PACKET);
 
     DecodeEthernet(&tv, &dtv, &p, raw_eth, sizeof(raw_eth), NULL);
 
diff --git a/src/decode-gre.c b/src/decode-gre.c
index d50e019..fec4f4d 100644
--- a/src/decode-gre.c
+++ b/src/decode-gre.c
@@ -196,7 +196,7 @@ void DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u
                     Packet *tp = PacketPseudoPktSetup(p, pkt + header_len,
                             len - header_len, IPPROTO_IP);
                     if (tp != NULL) {
-                        DecodeTunnel(tv, dtv, tp, tp->pkt, tp->pktlen, pq);
+                        DecodeTunnel(tv, dtv, tp, GET_PKT_DATA(tp), GET_PKT_LEN(tp), pq);
                         PacketEnqueue(pq,tp);
                     }
                 }
@@ -209,7 +209,7 @@ void DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u
                     Packet *tp = PacketPseudoPktSetup(p, pkt + header_len,
                             len - header_len, PPP_OVER_GRE);
                     if (tp != NULL) {
-                        DecodeTunnel(tv, dtv, tp, tp->pkt, tp->pktlen, pq);
+                        DecodeTunnel(tv, dtv, tp, GET_PKT_DATA(tp), GET_PKT_LEN(tp), pq);
                         PacketEnqueue(pq,tp);
                     }
                 }
@@ -222,7 +222,7 @@ void DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u
                     Packet *tp = PacketPseudoPktSetup(p, pkt + header_len,
                             len - header_len, IPPROTO_IPV6);
                     if (tp != NULL) {
-                        DecodeTunnel(tv, dtv, tp, tp->pkt, tp->pktlen, pq);
+                        DecodeTunnel(tv, dtv, tp, GET_PKT_DATA(tp), GET_PKT_LEN(tp), pq);
                         PacketEnqueue(pq,tp);
                     }
                 }
@@ -235,7 +235,7 @@ void DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u
                     Packet *tp = PacketPseudoPktSetup(p, pkt + header_len,
                             len - header_len, VLAN_OVER_GRE);
                     if (tp != NULL) {
-                        DecodeTunnel(tv, dtv, tp, tp->pkt, tp->pktlen, pq);
+                        DecodeTunnel(tv, dtv, tp, GET_PKT_DATA(tp), GET_PKT_LEN(tp), pq);
                         PacketEnqueue(pq,tp);
                     }
                 }
@@ -262,7 +262,7 @@ static int DecodeGREtest01 (void)   {
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     DecodeGRE(&tv, &dtv, &p, raw_gre, sizeof(raw_gre), NULL);
@@ -299,7 +299,7 @@ static int DecodeGREtest02 (void)   {
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     DecodeGRE(&tv, &dtv, &p, raw_gre, sizeof(raw_gre), NULL);
@@ -337,7 +337,7 @@ static int DecodeGREtest03 (void)   {
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     DecodeGRE(&tv, &dtv, &p, raw_gre, sizeof(raw_gre), NULL);
diff --git a/src/decode-icmpv4.c b/src/decode-icmpv4.c
index 562c9e0..cbb2d8e 100644
--- a/src/decode-icmpv4.c
+++ b/src/decode-icmpv4.c
@@ -307,7 +307,7 @@ static int DecodeICMPV4test01(void) {
 
     memset(&ip4h, 0, sizeof(IPV4Hdr));
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&ip4h, 0, sizeof(IPV4Hdr));
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
@@ -355,7 +355,7 @@ static int DecodeICMPV4test02(void) {
 
     memset(&ip4h, 0, sizeof(IPV4Hdr));
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     FlowInitConfig(FLOW_QUIET);
@@ -400,7 +400,7 @@ static int DecodeICMPV4test03(void) {
 
     memset(&ip4h, 0, sizeof(IPV4Hdr));
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     FlowInitConfig(FLOW_QUIET);
@@ -468,7 +468,7 @@ static int DecodeICMPV4test04(void) {
 
     memset(&ip4h, 0, sizeof(IPV4Hdr));
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     FlowInitConfig(FLOW_QUIET);
@@ -569,7 +569,7 @@ static int ICMPV4InvalidType07(void) {
 
     memset(&ip4h, 0, sizeof(IPV4Hdr));
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     FlowInitConfig(FLOW_QUIET);
@@ -609,7 +609,7 @@ static int DecodeICMPV4test08(void) {
 
     memset(&ip4h, 0, sizeof(IPV4Hdr));
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     FlowInitConfig(FLOW_QUIET);
diff --git a/src/decode-icmpv6.c b/src/decode-icmpv6.c
index 83c634f..71b0a61 100644
--- a/src/decode-icmpv6.c
+++ b/src/decode-icmpv6.c
@@ -362,7 +362,7 @@ static int ICMPV6ParamProbTest01(void)
     ipv6dst = (uint32_t*) &raw_ipv6[24];
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip6h, 0, sizeof(IPV6Hdr));
 
@@ -430,7 +430,7 @@ static int ICMPV6PktTooBigTest01(void)
     ipv6dst = (uint32_t*) &raw_ipv6[24];
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip6h, 0, sizeof(IPV6Hdr));
 
@@ -501,7 +501,7 @@ static int ICMPV6TimeExceedTest01(void)
 
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip6h, 0, sizeof(IPV6Hdr));
 
@@ -573,7 +573,7 @@ static int ICMPV6DestUnreachTest01(void)
 
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip6h, 0, sizeof(IPV6Hdr));
 
@@ -632,7 +632,7 @@ static int ICMPV6EchoReqTest01(void)
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip6h, 0, sizeof(IPV6Hdr));
 
@@ -681,7 +681,7 @@ static int ICMPV6EchoRepTest01(void)
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip6h, 0, sizeof(IPV6Hdr));
 
@@ -737,7 +737,7 @@ static int ICMPV6ParamProbTest02(void)
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip6h, 0, sizeof(IPV6Hdr));
 
@@ -794,7 +794,7 @@ static int ICMPV6PktTooBigTest02(void)
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip6h, 0, sizeof(IPV6Hdr));
 
@@ -842,7 +842,7 @@ static int ICMPV6TimeExceedTest02(void)
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip6h, 0, sizeof(IPV6Hdr));
 
@@ -887,7 +887,7 @@ static int ICMPV6DestUnreachTest02(void)
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip6h, 0, sizeof(IPV6Hdr));
 
@@ -928,7 +928,7 @@ static int ICMPV6EchoReqTest02(void)
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip6h, 0, sizeof(IPV6Hdr));
 
@@ -969,7 +969,7 @@ static int ICMPV6EchoRepTest02(void)
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip6h, 0, sizeof(IPV6Hdr));
 
@@ -1013,7 +1013,7 @@ static int ICMPV6PayloadTest01(void)
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip6h, 0, sizeof(IPV6Hdr));
 
diff --git a/src/decode-ipv4.c b/src/decode-ipv4.c
index 22963dc..2235232 100644
--- a/src/decode-ipv4.c
+++ b/src/decode-ipv4.c
@@ -565,7 +565,7 @@ void DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
                             IPV4_GET_IPPROTO(p));
                     if (tp != NULL) {
                         /* send that to the Tunnel decoder */
-                        DecodeTunnel(tv, dtv, tp, tp->pkt, tp->pktlen, pq);
+                        DecodeTunnel(tv, dtv, tp, GET_PKT_DATA(tp), GET_PKT_LEN(tp), pq);
 
                         /* add the tp to the packet queue. */
                         PacketEnqueue(pq,tp);
@@ -584,7 +584,7 @@ void DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
         Packet *rp = Defrag(tv, dtv, NULL, p);
         if (rp != NULL) {
             /* Got re-assembled packet, re-run through decoder. */
-            DecodeIPV4(tv, dtv, rp, rp->pkt, rp->pktlen, pq);
+            DecodeIPV4(tv, dtv, rp, GET_PKT_DATA(rp), GET_PKT_LEN(rp), pq);
             PacketEnqueue(pq, rp);
         }
     }
@@ -631,7 +631,7 @@ int DecodeIPV4OptionsNONETest01(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     if (rc != 0) {
@@ -639,7 +639,7 @@ int DecodeIPV4OptionsNONETest01(void) {
         return 0;
     }
 
-    for (i = 0; i < (uint16_t)sizeof(Packet); i++) {
+    for (i = 0; i < (uint16_t)SIZE_OF_PACKET; i++) {
         if (*data) {
             /* Should not have modified packet data */
             //printf("Data modified at offset %" PRIu16 "\n", i);
@@ -663,7 +663,7 @@ int DecodeIPV4OptionsEOLTest01(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     if (rc != 0) {
@@ -671,7 +671,7 @@ int DecodeIPV4OptionsEOLTest01(void) {
         return 0;
     }
 
-    for (i = 0; i < (uint16_t)sizeof(Packet); i++) {
+    for (i = 0; i < (uint16_t)SIZE_OF_PACKET; i++) {
         if (*data) {
             /* Should not have modified packet data */
             //printf("Data modified at offset %" PRIu16 "\n", i);
@@ -695,7 +695,7 @@ int DecodeIPV4OptionsNOPTest01(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     if (rc != 0) {
@@ -703,7 +703,7 @@ int DecodeIPV4OptionsNOPTest01(void) {
         return 0;
     }
 
-    for (i = 0; i < (uint16_t)sizeof(Packet); i++) {
+    for (i = 0; i < (uint16_t)SIZE_OF_PACKET; i++) {
         if (*data) {
             /* Should not have modified packet data */
             //printf("Data modified at offset %" PRIu16 "\n", i);
@@ -729,7 +729,7 @@ int DecodeIPV4OptionsRRTest01(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rr, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -760,7 +760,7 @@ int DecodeIPV4OptionsRRTest02(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rr, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -786,7 +786,7 @@ int DecodeIPV4OptionsRRTest03(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rr, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -812,7 +812,7 @@ int DecodeIPV4OptionsRRTest04(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rr, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -834,7 +834,7 @@ int DecodeIPV4OptionsQSTest01(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",qs=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_qs, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -861,7 +861,7 @@ int DecodeIPV4OptionsQSTest02(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",qs=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_qs, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -887,7 +887,7 @@ int DecodeIPV4OptionsTSTest01(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ts=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ts, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -918,7 +918,7 @@ int DecodeIPV4OptionsTSTest02(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ts=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ts, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -944,7 +944,7 @@ int DecodeIPV4OptionsTSTest03(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ts=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ts, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -970,7 +970,7 @@ int DecodeIPV4OptionsTSTest04(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ts=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ts, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -993,7 +993,7 @@ int DecodeIPV4OptionsSECTest01(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",sec=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_sec, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -1021,7 +1021,7 @@ int DecodeIPV4OptionsSECTest02(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",sec=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_sec, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -1047,7 +1047,7 @@ int DecodeIPV4OptionsLSRRTest01(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",lsrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_lsrr, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -1078,7 +1078,7 @@ int DecodeIPV4OptionsLSRRTest02(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",lsrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_lsrr, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -1104,7 +1104,7 @@ int DecodeIPV4OptionsLSRRTest03(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",lsrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_lsrr, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -1130,7 +1130,7 @@ int DecodeIPV4OptionsLSRRTest04(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",lsrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_lsrr, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -1154,7 +1154,7 @@ int DecodeIPV4OptionsCIPSOTest01(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_cipso, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -1181,7 +1181,7 @@ int DecodeIPV4OptionsSIDTest01(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",sid=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_sid, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -1208,7 +1208,7 @@ int DecodeIPV4OptionsSIDTest02(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",sid=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_sid, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -1234,7 +1234,7 @@ int DecodeIPV4OptionsSSRRTest01(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ssrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ssrr, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -1265,7 +1265,7 @@ int DecodeIPV4OptionsSSRRTest02(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ssrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ssrr, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -1291,7 +1291,7 @@ int DecodeIPV4OptionsSSRRTest03(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ssrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ssrr, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -1317,7 +1317,7 @@ int DecodeIPV4OptionsSSRRTest04(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",ssrr=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_ssrr, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -1339,7 +1339,7 @@ int DecodeIPV4OptionsRTRALTTest01(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rtralt=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rtralt, (uintmax_t)&p.IPV4_OPTS[0]);
@@ -1366,7 +1366,7 @@ int DecodeIPV4OptionsRTRALTTest02(void) {
     int rc;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     rc = DecodeIPV4Options(&tv, &p, raw_opts, sizeof(raw_opts));
     //printf("rc=%d,cnt=%" PRIu16 ",type=%" PRIu8 ",len=%" PRIu8 ",rtralt=%" PRIuMAX "/%" PRIuMAX "\n", rc, p.IPV4_OPTS_CNT, p.IPV4_OPTS[0].type, p.IPV4_OPTS[0].len, (uintmax_t)p.ip4vars.o_rtralt, (uintmax_t)&p.IPV4_OPTS[0]);
diff --git a/src/decode-ipv6.c b/src/decode-ipv6.c
index 870062c..b3a5776 100644
--- a/src/decode-ipv6.c
+++ b/src/decode-ipv6.c
@@ -456,7 +456,7 @@ void DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
     if (IPV6_EXTHDR_ISSET_FH(p)) {
         Packet *rp = Defrag(tv, dtv, NULL, p);
         if (rp != NULL) {
-            DecodeIPV6(tv, dtv, rp, rp->pkt, rp->pktlen, pq);
+            DecodeIPV6(tv, dtv, rp, GET_PKT_DATA(rp), GET_PKT_LEN(rp), pq);
             PacketEnqueue(pq, rp);
 
             /* Not really a tunnel packet, but we're piggybacking that
diff --git a/src/decode-ppp.c b/src/decode-ppp.c
index b848a46..0473459 100644
--- a/src/decode-ppp.c
+++ b/src/decode-ppp.c
@@ -136,7 +136,7 @@ static int DecodePPPtest01 (void)   {
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     DecodePPP(&tv, &dtv, &p, raw_ppp, sizeof(raw_ppp), NULL);
@@ -165,7 +165,7 @@ static int DecodePPPtest02 (void)   {
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     DecodePPP(&tv, &dtv, &p, raw_ppp, sizeof(raw_ppp), NULL);
@@ -196,7 +196,7 @@ static int DecodePPPtest03 (void)   {
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     FlowInitConfig(FLOW_QUIET);
@@ -246,7 +246,7 @@ static int DecodePPPtest04 (void)   {
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     FlowInitConfig(FLOW_QUIET);
diff --git a/src/decode-pppoe.c b/src/decode-pppoe.c
index 1a9780e..1c0f81d 100644
--- a/src/decode-pppoe.c
+++ b/src/decode-pppoe.c
@@ -224,7 +224,7 @@ static int DecodePPPOEtest01 (void)   {
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     DecodePPPOESession(&tv, &dtv, &p, raw_pppoe, sizeof(raw_pppoe), NULL);
@@ -259,7 +259,7 @@ static int DecodePPPOEtest02 (void)   {
     int ret = 0;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     FlowInitConfig(FLOW_QUIET);
@@ -303,7 +303,7 @@ static int DecodePPPOEtest03 (void)   {
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     DecodePPPOEDiscovery(&tv, &dtv, &p, raw_pppoe, sizeof(raw_pppoe), NULL);
@@ -330,7 +330,7 @@ static int DecodePPPOEtest04 (void)   {
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     DecodePPPOEDiscovery(&tv, &dtv, &p, raw_pppoe, sizeof(raw_pppoe), NULL);
@@ -361,7 +361,7 @@ static int DecodePPPOEtest05 (void)   {
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     DecodePPPOEDiscovery(&tv, &dtv, &p, raw_pppoe, sizeof(raw_pppoe), NULL);
diff --git a/src/decode-raw.c b/src/decode-raw.c
index d9581f3..a90059c 100644
--- a/src/decode-raw.c
+++ b/src/decode-raw.c
@@ -43,10 +43,10 @@ void DecodeRaw(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, u
 
     if (IP_GET_RAW_VER(pkt) == 4) {
         SCLogDebug("IPV4 Packet");
-        DecodeIPV4(tv, dtv, p, p->pkt, p->pktlen, pq);
+        DecodeIPV4(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq);
     } else if (IP_GET_RAW_VER(pkt) == 6) {
         SCLogDebug("IPV6 Packet");
-        DecodeIPV6(tv, dtv, p, p->pkt, p->pktlen, pq);
+        DecodeIPV6(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq);
     } else {
         SCLogDebug("Unknown ip version %" PRIu8 "", IP_GET_RAW_VER(pkt));
         DECODER_SET_EVENT(p,IPRAW_INVALID_IPV);
@@ -82,10 +82,10 @@ static int DecodeRawTest01 (void)   {
 
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&tv,  0, sizeof(ThreadVars));
-    memset(&p,   0, sizeof(Packet));
+    memset(&p,   0, SIZE_OF_PACKET);
 
-    p.pktlen = sizeof(raw_ip);
-    memcpy(p.pkt, raw_ip, p.pktlen);
+    if (PacketCopyData(&p, raw_ip, sizeof(raw_ip)) == -1)
+        return 1;
 
     FlowInitConfig(FLOW_QUIET);
 
@@ -121,10 +121,10 @@ static int DecodeRawTest02 (void)   {
 
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&tv,  0, sizeof(ThreadVars));
-    memset(&p,   0, sizeof(Packet));
+    memset(&p,   0, SIZE_OF_PACKET);
 
-    p.pktlen = sizeof(raw_ip);
-    memcpy(p.pkt, raw_ip, p.pktlen);
+    if (PacketCopyData(&p, raw_ip, sizeof(raw_ip)) == -1)
+        return 1;
 
     FlowInitConfig(FLOW_QUIET);
 
@@ -160,10 +160,10 @@ static int DecodeRawTest03 (void)   {
 
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&tv,  0, sizeof(ThreadVars));
-    memset(&p,   0, sizeof(Packet));
+    memset(&p,   0, SIZE_OF_PACKET);
 
-    p.pktlen = sizeof(raw_ip);
-    memcpy(p.pkt, raw_ip, p.pktlen);
+    if (PacketCopyData(&p, raw_ip, sizeof(raw_ip)) == -1)
+        return 1;
 
     FlowInitConfig(FLOW_QUIET);
 
diff --git a/src/decode-tcp.c b/src/decode-tcp.c
index 995df94..79e49e2 100644
--- a/src/decode-tcp.c
+++ b/src/decode-tcp.c
@@ -285,7 +285,7 @@ static int TCPGetWscaleTest01(void)
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip4h, 0, sizeof(IPV4Hdr));
 
@@ -329,7 +329,7 @@ static int TCPGetWscaleTest02(void)
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip4h, 0, sizeof(IPV4Hdr));
 
@@ -371,7 +371,7 @@ static int TCPGetWscaleTest03(void)
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip4h, 0, sizeof(IPV4Hdr));
 
diff --git a/src/decode-vlan.c b/src/decode-vlan.c
index afea813..67a615f 100644
--- a/src/decode-vlan.c
+++ b/src/decode-vlan.c
@@ -109,7 +109,7 @@ static int DecodeVLANtest01 (void)   {
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     DecodeVLAN(&tv, &dtv, &p, raw_vlan, sizeof(raw_vlan), NULL);
@@ -141,7 +141,7 @@ static int DecodeVLANtest02 (void)   {
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     DecodeVLAN(&tv, &dtv, &p, raw_vlan, sizeof(raw_vlan), NULL);
@@ -174,7 +174,7 @@ static int DecodeVLANtest03 (void)   {
     DecodeThreadVars dtv;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
 
     FlowInitConfig(FLOW_QUIET);
diff --git a/src/defrag.c b/src/defrag.c
index 4165560..15e1c38 100644
--- a/src/defrag.c
+++ b/src/defrag.c
@@ -557,8 +557,9 @@ Defrag4Reassemble(ThreadVars *tv, DefragContext *dc, DefragTracker *tracker,
         if (frag->offset == 0) {
             /* This is the first packet, we use this packets link and
              * IPv4 header. We also copy in its data. */
-            memcpy(rp->pkt, frag->pkt, frag->len);
-            rp->ip4h = (IPV4Hdr *)(rp->pkt + frag->ip_hdr_offset);
+            if (PacketCopyData(rp, frag->pkt, frag->len) == -1)
+                return NULL;
+            rp->ip4h = (IPV4Hdr *)(GET_PKT_DATA(rp) + frag->ip_hdr_offset);
             hlen = frag->hlen;
             ip_hdr_offset = frag->ip_hdr_offset;
 
@@ -570,13 +571,15 @@ Defrag4Reassemble(ThreadVars *tv, DefragContext *dc, DefragTracker *tracker,
         }
         else {
             int pkt_end = fragmentable_offset + frag->offset + frag->data_len;
-            if (pkt_end > (int)sizeof(rp->pkt)) {
+            if (pkt_end > (int)MAX_PAYLOAD_SIZE) {
                 SCLogWarning(SC_ERR_REASSEMBLY, "Failed re-assemble fragmented packet, exceeds size of packet buffer.");
                 goto remove_tracker;
             }
-            memcpy(rp->pkt + fragmentable_offset + frag->offset + frag->ltrim,
+            if (PacketCopyDataOffset(rp, fragmentable_offset + frag->offset + frag->ltrim,
                 frag->pkt + frag->data_offset + frag->ltrim,
-                frag->data_len - frag->ltrim);
+                frag->data_len - frag->ltrim) == -1) {
+                return NULL;
+            }
             if (frag->offset + frag->data_len > fragmentable_len)
                 fragmentable_len = frag->offset + frag->data_len;
         }
@@ -588,7 +591,7 @@ Defrag4Reassemble(ThreadVars *tv, DefragContext *dc, DefragTracker *tracker,
     rp->ip4h->ip_off = 0;
     rp->ip4h->ip_csum = FixChecksum(rp->ip4h->ip_csum,
         old, rp->ip4h->ip_len + rp->ip4h->ip_off);
-    rp->pktlen = ip_hdr_offset + hlen + fragmentable_len;
+    SET_PKT_LEN(p, ip_hdr_offset + hlen + fragmentable_len);
     IPV4_CACHE_INIT(rp);
 
 remove_tracker:
@@ -673,11 +676,13 @@ Defrag6Reassemble(ThreadVars *tv, DefragContext *dc, DefragTracker *tracker,
             /* This is the first packet, we use this packets link and
              * IPv6 headers. We also copy in its data, but remove the
              * fragmentation header. */
-            memcpy(rp->pkt, frag->pkt, frag->frag_hdr_offset);
-            memcpy(rp->pkt + frag->frag_hdr_offset,
+            if (PacketCopyData(rp, frag->pkt, frag->frag_hdr_offset) == -1)
+                goto remove_tracker;
+            if (PacketCopyDataOffset(rp, frag->frag_hdr_offset,
                 frag->pkt + frag->frag_hdr_offset + sizeof(IPV6FragHdr),
-                frag->data_len);
-            rp->ip6h = (IPV6Hdr *)(rp->pkt + frag->ip_hdr_offset);
+                frag->data_len) == -1)
+                goto remove_tracker;
+            rp->ip6h = (IPV6Hdr *)(GET_PKT_DATA(rp) + frag->ip_hdr_offset);
             ip_hdr_offset = frag->ip_hdr_offset;
 
             /* This is the start of the fragmentable portion of the
@@ -687,9 +692,10 @@ Defrag6Reassemble(ThreadVars *tv, DefragContext *dc, DefragTracker *tracker,
             fragmentable_len = frag->data_len;
         }
         else {
-            memcpy(rp->pkt + fragmentable_offset + frag->offset + frag->ltrim,
+            if (PacketCopyDataOffset(rp, fragmentable_offset + frag->offset + frag->ltrim,
                 frag->pkt + frag->data_offset + frag->ltrim,
-                frag->data_len - frag->ltrim);
+                frag->data_len - frag->ltrim) == -1)
+                goto remove_tracker;
             if (frag->offset + frag->data_len > fragmentable_len)
                 fragmentable_len = frag->offset + frag->data_len;
         }
@@ -697,7 +703,7 @@ Defrag6Reassemble(ThreadVars *tv, DefragContext *dc, DefragTracker *tracker,
     BUG_ON(rp->ip6h == NULL);
     rp->ip6h->s_ip6_plen = htons(fragmentable_len);
     rp->ip6h->s_ip6_nxt = next_hdr;
-    rp->pktlen = ip_hdr_offset + sizeof(IPV6Hdr) + fragmentable_len;
+    SET_PKT_LEN(rp, ip_hdr_offset + sizeof(IPV6Hdr) + fragmentable_len);
     IPV6_CACHE_INIT(rp);
 
 remove_tracker:
@@ -753,10 +759,10 @@ DefragInsertFrag(ThreadVars *tv, DecodeThreadVars *dtv, DefragContext *dc,
         more_frags = IPV4_GET_MF(p);
         frag_offset = IPV4_GET_IPOFFSET(p) << 3;
         hlen = IPV4_GET_HLEN(p);
-        data_offset = (uint8_t *)p->ip4h + hlen - p->pkt;
+        data_offset = (uint8_t *)p->ip4h + hlen - GET_PKT_DATA(p);
         data_len = IPV4_GET_IPLEN(p) - hlen;
         frag_end = frag_offset + data_len;
-        ip_hdr_offset = (uint8_t *)p->ip4h - p->pkt;
+        ip_hdr_offset = (uint8_t *)p->ip4h - GET_PKT_DATA(p);
 
         /* Ignore fragment if the end of packet extends past the
          * maximum size of a packet. */
@@ -768,13 +774,13 @@ DefragInsertFrag(ThreadVars *tv, DecodeThreadVars *dtv, DefragContext *dc,
     else if (tracker->af == AF_INET6) {
         more_frags = IPV6_EXTHDR_GET_FH_FLAG(p);
         frag_offset = IPV6_EXTHDR_GET_FH_OFFSET(p);
-        data_offset = (uint8_t *)p->ip6eh.ip6fh + sizeof(IPV6FragHdr) - p->pkt;
+        data_offset = (uint8_t *)p->ip6eh.ip6fh + sizeof(IPV6FragHdr) - GET_PKT_DATA(p);
         data_len = IPV6_GET_PLEN(p) - (
             ((uint8_t *)p->ip6eh.ip6fh + sizeof(IPV6FragHdr)) -
                 ((uint8_t *)p->ip6h + sizeof(IPV6Hdr)));
         frag_end = frag_offset + data_len;
-        ip_hdr_offset = (uint8_t *)p->ip6h - p->pkt;
-        frag_hdr_offset = (uint8_t *)p->ip6eh.ip6fh - p->pkt;
+        ip_hdr_offset = (uint8_t *)p->ip6h - GET_PKT_DATA(p);
+        frag_hdr_offset = (uint8_t *)p->ip6eh.ip6fh - GET_PKT_DATA(p);
 
         /* Ignore fragment if the end of packet extends past the
          * maximum size of a packet. */
@@ -893,15 +899,15 @@ insert:
     if (new == NULL) {
         goto done;
     }
-    new->pkt = SCMalloc(p->pktlen);
+    new->pkt = SCMalloc(GET_PKT_LEN(p));
     if (new->pkt == NULL) {
         SCMutexLock(&dc->frag_pool_lock);
         PoolReturn(dc->frag_pool, new);
         SCMutexUnlock(&dc->frag_pool_lock);
         goto done;
     }
-    memcpy(new->pkt, p->pkt + ltrim, p->pktlen - ltrim);
-    new->len = p->pktlen - ltrim;
+    memcpy(new->pkt, GET_PKT_DATA(p) + ltrim, GET_PKT_LEN(p) - ltrim);
+    new->len = GET_PKT_LEN(p) - ltrim;
     new->hlen = hlen;
     new->offset = frag_offset + ltrim;
     new->data_offset = data_offset;
@@ -1211,32 +1217,45 @@ BuildTestPacket(uint16_t id, uint16_t off, int mf, const char content,
     Packet *p = NULL;
     int hlen = 20;
     int ttl = 64;
+    uint8_t *pcontent;
+    IPV4Hdr ip4h;
 
-    p = SCCalloc(1, sizeof(*p));
+    p = SCCalloc(1, sizeof(*p) + default_packet_size);
     if (p == NULL)
         return NULL;
+    p->pkt = ((uint8_t *)p) + sizeof(*p);
     gettimeofday(&p->ts, NULL);
-    p->ip4h = (IPV4Hdr *)p->pkt;
-    p->ip4h->ip_verhl = 4 << 4;
-    p->ip4h->ip_verhl |= hlen >> 2;
-    p->ip4h->ip_len = htons(hlen + content_len);
-    p->ip4h->ip_id = htons(id);
-    p->ip4h->ip_off = htons(off);
+    //p->ip4h = (IPV4Hdr *)GET_PKT_DATA(p);
+    ip4h.ip_verhl = 4 << 4;
+    ip4h.ip_verhl |= hlen >> 2;
+    ip4h.ip_len = htons(hlen + content_len);
+    ip4h.ip_id = htons(id);
+    ip4h.ip_off = htons(off);
     if (mf)
-        p->ip4h->ip_off = htons(IP_MF | off);
+        ip4h.ip_off = htons(IP_MF | off);
     else
-        p->ip4h->ip_off = htons(off);
-    p->ip4h->ip_ttl = ttl;
-    p->ip4h->ip_proto = IPPROTO_ICMP;
+        ip4h.ip_off = htons(off);
+    ip4h.ip_ttl = ttl;
+    ip4h.ip_proto = IPPROTO_ICMP;
+
+    ip4h.ip_src.s_addr = 0x01010101; /* 1.1.1.1 */
+    ip4h.ip_dst.s_addr = 0x02020202; /* 2.2.2.2 */
 
-    p->ip4h->ip_src.s_addr = 0x01010101; /* 1.1.1.1 */
-    p->ip4h->ip_dst.s_addr = 0x02020202; /* 2.2.2.2 */
+    /* copy content_len crap, we need full length */
+    PacketCopyData(p, (uint8_t *)&ip4h, sizeof(ip4h) + content_len);
+    p->ip4h = (IPV4Hdr *)GET_PKT_DATA(p);
     SET_IPV4_SRC_ADDR(p, &p->src);
     SET_IPV4_DST_ADDR(p, &p->dst);
-    memset(p->pkt + hlen, content, content_len);
-    p->pktlen = hlen + content_len;
 
-    p->ip4h->ip_csum = IPV4CalculateChecksum((uint16_t *)p->pkt, hlen);
+    pcontent = SCCalloc(1, content_len);
+    if (pcontent == NULL)
+        return NULL;
+    memset(pcontent, content, content_len);
+    PacketCopyDataOffset(p, hlen, pcontent, content_len);
+    SET_PKT_LEN(p, hlen + content_len);
+    SCFree(pcontent);
+
+    p->ip4h->ip_csum = IPV4CalculateChecksum((uint16_t *)GET_PKT_DATA(p), hlen);
 
     /* Self test. */
     IPV4_CACHE_INIT(p);
@@ -1269,36 +1288,46 @@ IPV6BuildTestPacket(uint32_t id, uint16_t off, int mf, const char content,
     int content_len)
 {
     Packet *p = NULL;
+    uint8_t *pcontent;
+    IPV6Hdr ip6h;
 
-    p = SCCalloc(1, sizeof(*p));
+    p = SCCalloc(1, sizeof(*p) + default_packet_size);
     if (p == NULL)
         return NULL;
+    p->pkt = ((uint8_t *)p) + sizeof(*p);
     gettimeofday(&p->ts, NULL);
 
-    p->ip6h = (IPV6Hdr *)p->pkt;
-    IPV6_SET_RAW_VER(p->ip6h, 6);
-    p->ip6h->s_ip6_nxt = 44;
-    p->ip6h->s_ip6_hlim = 2;
+    ip6h.s_ip6_nxt = 44;
+    ip6h.s_ip6_hlim = 2;
 
     /* Source and dest address - very bogus addresses. */
-    p->ip6h->ip6_src[0] = 0x01010101;
-    p->ip6h->ip6_src[1] = 0x01010101;
-    p->ip6h->ip6_src[2] = 0x01010101;
-    p->ip6h->ip6_src[3] = 0x01010101;
-    p->ip6h->ip6_dst[0] = 0x02020202;
-    p->ip6h->ip6_dst[1] = 0x02020202;
-    p->ip6h->ip6_dst[2] = 0x02020202;
-    p->ip6h->ip6_dst[3] = 0x02020202;
-
+    ip6h.ip6_src[0] = 0x01010101;
+    ip6h.ip6_src[1] = 0x01010101;
+    ip6h.ip6_src[2] = 0x01010101;
+    ip6h.ip6_src[3] = 0x01010101;
+    ip6h.ip6_dst[0] = 0x02020202;
+    ip6h.ip6_dst[1] = 0x02020202;
+    ip6h.ip6_dst[2] = 0x02020202;
+    ip6h.ip6_dst[3] = 0x02020202;
+
+    /* copy content_len crap, we need full length */
+    PacketCopyData(p, (uint8_t *)&ip6h, sizeof(IPV6Hdr) + sizeof(IPV6FragHdr) + content_len);
+
+    p->ip6h = (IPV6Hdr *)GET_PKT_DATA(p);
+    IPV6_SET_RAW_VER(p->ip6h, 6);
     /* Fragmentation header. */
-    p->ip6eh.ip6fh = (IPV6FragHdr *)(p->pkt + sizeof(IPV6Hdr));
+    p->ip6eh.ip6fh = (IPV6FragHdr *)(GET_PKT_DATA(p) + sizeof(IPV6Hdr));
     p->ip6eh.ip6fh->ip6fh_nxt = IPPROTO_ICMP;
     p->ip6eh.ip6fh->ip6fh_ident = htonl(id);
     p->ip6eh.ip6fh->ip6fh_offlg = htons((off << 3) | mf);
 
-    memset(p->pkt + sizeof(IPV6Hdr) + sizeof(IPV6FragHdr), content,
-        content_len);
-    p->pktlen = sizeof(IPV6Hdr) + sizeof(IPV6FragHdr) + content_len;
+    pcontent = SCCalloc(1, content_len);
+    if (pcontent == NULL)
+        return NULL;
+    memset(pcontent, content, content_len);
+    PacketCopyDataOffset(p, sizeof(IPV6Hdr) + sizeof(IPV6FragHdr), pcontent, content_len);
+    SET_PKT_LEN(p, sizeof(IPV6Hdr) + sizeof(IPV6FragHdr) + content_len);
+    SCFree(pcontent);
 
     p->ip6h->s_ip6_plen = htons(sizeof(IPV6FragHdr) + content_len);
 
@@ -1368,19 +1397,19 @@ DefragInOrderSimpleTest(void)
 
     /* 20 bytes in we should find 8 bytes of A. */
     for (i = 20; i < 20 + 8; i++) {
-        if (reassembled->pkt[i] != 'A')
+        if (GET_PKT_DATA(reassembled)[i] != 'A')
             goto end;
     }
 
     /* 28 bytes in we should find 8 bytes of B. */
     for (i = 28; i < 28 + 8; i++) {
-        if (reassembled->pkt[i] != 'B')
+        if (GET_PKT_DATA(reassembled)[i] != 'B')
             goto end;
     }
 
     /* And 36 bytes in we should find 3 bytes of C. */
     for (i = 36; i < 36 + 3; i++) {
-        if (reassembled->pkt[i] != 'C')
+        if (GET_PKT_DATA(reassembled)[i] != 'C')
             goto end;
     }
 
@@ -1447,19 +1476,19 @@ DefragReverseSimpleTest(void)
 
     /* 20 bytes in we should find 8 bytes of A. */
     for (i = 20; i < 20 + 8; i++) {
-        if (reassembled->pkt[i] != 'A')
+        if (GET_PKT_DATA(reassembled)[i] != 'A')
             goto end;
     }
 
     /* 28 bytes in we should find 8 bytes of B. */
     for (i = 28; i < 28 + 8; i++) {
-        if (reassembled->pkt[i] != 'B')
+        if (GET_PKT_DATA(reassembled)[i] != 'B')
             goto end;
     }
 
     /* And 36 bytes in we should find 3 bytes of C. */
     for (i = 36; i < 36 + 3; i++) {
-        if (reassembled->pkt[i] != 'C')
+        if (GET_PKT_DATA(reassembled)[i] != 'C')
             goto end;
     }
 
@@ -1524,19 +1553,19 @@ IPV6DefragInOrderSimpleTest(void)
 
     /* 40 bytes in we should find 8 bytes of A. */
     for (i = 40; i < 40 + 8; i++) {
-        if (reassembled->pkt[i] != 'A')
+        if (GET_PKT_DATA(reassembled)[i] != 'A')
             goto end;
     }
 
     /* 28 bytes in we should find 8 bytes of B. */
     for (i = 48; i < 48 + 8; i++) {
-        if (reassembled->pkt[i] != 'B')
+        if (GET_PKT_DATA(reassembled)[i] != 'B')
             goto end;
     }
 
     /* And 36 bytes in we should find 3 bytes of C. */
     for (i = 56; i < 56 + 3; i++) {
-        if (reassembled->pkt[i] != 'C')
+        if (GET_PKT_DATA(reassembled)[i] != 'C')
             goto end;
     }
 
@@ -1593,19 +1622,19 @@ IPV6DefragReverseSimpleTest(void)
 
     /* 40 bytes in we should find 8 bytes of A. */
     for (i = 40; i < 40 + 8; i++) {
-        if (reassembled->pkt[i] != 'A')
+        if (GET_PKT_DATA(reassembled)[i] != 'A')
             goto end;
     }
 
     /* 28 bytes in we should find 8 bytes of B. */
     for (i = 48; i < 48 + 8; i++) {
-        if (reassembled->pkt[i] != 'B')
+        if (GET_PKT_DATA(reassembled)[i] != 'B')
             goto end;
     }
 
     /* And 36 bytes in we should find 3 bytes of C. */
     for (i = 56; i < 56 + 3; i++) {
-        if (reassembled->pkt[i] != 'C')
+        if (GET_PKT_DATA(reassembled)[i] != 'C')
             goto end;
     }
 
@@ -1726,7 +1755,7 @@ DefragDoSturgesNovakTest(int policy, u_char *expected, size_t expected_len)
     if (IPV4_GET_IPLEN(reassembled) != 20 + 192)
         goto end;
 
-    if (memcmp(reassembled->pkt + 20, expected, expected_len) != 0)
+    if (memcmp(GET_PKT_DATA(reassembled) + 20, expected, expected_len) != 0)
         goto end;
     SCFree(reassembled);
 
@@ -1917,7 +1946,7 @@ IPV6DefragDoSturgesNovakTest(int policy, u_char *expected, size_t expected_len)
     Packet *reassembled = Defrag(NULL, NULL, dc, packets[16]);
     if (reassembled == NULL)
         goto end;
-    if (memcmp(reassembled->pkt + 40, expected, expected_len) != 0)
+    if (memcmp(GET_PKT_DATA(reassembled) + 40, expected, expected_len) != 0)
         goto end;
 
     if (IPV6_GET_PLEN(reassembled) != 192)
diff --git a/src/detect-bytetest.c b/src/detect-bytetest.c
index 96a454d..ff7247f 100644
--- a/src/detect-bytetest.c
+++ b/src/detect-bytetest.c
@@ -262,7 +262,7 @@ int DetectBytetestMatch(ThreadVars *t, DetectEngineThreadCtx *det_ctx,
      */
     if (data->flags & DETECT_BYTETEST_RELATIVE) {
         ptr = det_ctx->pkt_ptr;
-        len = p->pktlen - det_ctx->pkt_off;
+        len = GET_PKT_LEN(p) - det_ctx->pkt_off;
 
         /* No match if there is no relative base */
         if (ptr == NULL || len == 0) {
@@ -280,9 +280,9 @@ int DetectBytetestMatch(ThreadVars *t, DetectEngineThreadCtx *det_ctx,
     /* Validate that the to-be-extracted is within the packet
      * \todo Should this validate it is in the *payload*?
      */
-    if (ptr < p->pkt || data->nbytes > len) {
+    if (ptr < GET_PKT_DATA(p) || data->nbytes > len) {
         SCLogDebug("Data not within packet pkt=%p, ptr=%p, len=%d, nbytes=%d",
-                    p->pkt, ptr, len, data->nbytes);
+                    GET_PKT_DATA(p), ptr, len, data->nbytes);
         return 0;
     }
 
diff --git a/src/detect-content.c b/src/detect-content.c
index a31200b..225ca4b 100644
--- a/src/detect-content.c
+++ b/src/detect-content.c
@@ -687,7 +687,7 @@ int DetectContentLongPatternMatchTest(uint8_t *raw_eth_pkt, uint16_t pktsize, ch
     ThreadVars th_v;
     DetectEngineThreadCtx *det_ctx = NULL;
 
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&th_v, 0, sizeof(th_v));
 
diff --git a/src/detect-decode-event.c b/src/detect-decode-event.c
index ab30ed2..525416a 100644
--- a/src/detect-decode-event.c
+++ b/src/detect-decode-event.c
@@ -294,7 +294,7 @@ int DecodeEventTestParse06 (void) {
 
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
 
     DECODER_SET_EVENT(&p,PPP_PKT_TOO_SMALL);
 
diff --git a/src/detect-dsize.c b/src/detect-dsize.c
index d8bb113..0b70725 100644
--- a/src/detect-dsize.c
+++ b/src/detect-dsize.c
@@ -703,7 +703,7 @@ int DetectDsizeIcmpv6Test01 (void) {
     DetectEngineThreadCtx *det_ctx = NULL;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ip6h, 0, sizeof(IPV6Hdr));
     memset(&th_v, 0, sizeof(ThreadVars));
diff --git a/src/detect-engine-tag.c b/src/detect-engine-tag.c
index 2437796..0173049 100644
--- a/src/detect-engine-tag.c
+++ b/src/detect-engine-tag.c
@@ -348,7 +348,7 @@ void TagHandlePacket(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
                 /* update counters */
                 iter->last_ts.tv_sec = ts.tv_sec;
                 iter->packets++;
-                iter->bytes += p->pktlen;
+                iter->bytes += GET_PKT_LEN(p);
 
                 /* If this packet triggered the rule with tag, we dont need
                  * to log it (the alert will log it) */
@@ -482,7 +482,7 @@ void TagHandlePacket(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
         /* update counters */
         iter->last_ts.tv_sec = ts.tv_sec;
         iter->packets++;
-        iter->bytes += p->pktlen;
+        iter->bytes += GET_PKT_LEN(p);
 
         /* If this packet triggered the rule with tag, we dont need
          * to log it (the alert will log it) */
@@ -577,7 +577,7 @@ void TagHandlePacket(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
         /* update counters */
         iter->last_ts.tv_sec = ts.tv_sec;
         iter->packets++;
-        iter->bytes += p->pktlen;
+        iter->bytes += GET_PKT_LEN(p);
 
         /* If this packet triggered the rule with tag, we dont need
          * to log it (the alert will log it) */
diff --git a/src/detect-flags.c b/src/detect-flags.c
index af9fb3e..7463b14 100644
--- a/src/detect-flags.c
+++ b/src/detect-flags.c
@@ -543,7 +543,7 @@ static int FlagsTestParse03 (void) {
     TCPHdr tcph;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&ipv4h, 0, sizeof(IPV4Hdr));
     memset(&tcph, 0, sizeof(TCPHdr));
 
@@ -593,7 +593,7 @@ static int FlagsTestParse04 (void) {
     TCPHdr tcph;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&ipv4h, 0, sizeof(IPV4Hdr));
     memset(&tcph, 0, sizeof(TCPHdr));
 
@@ -643,7 +643,7 @@ static int FlagsTestParse05 (void) {
     TCPHdr tcph;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&ipv4h, 0, sizeof(IPV4Hdr));
     memset(&tcph, 0, sizeof(TCPHdr));
 
@@ -693,7 +693,7 @@ static int FlagsTestParse06 (void) {
     TCPHdr tcph;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&ipv4h, 0, sizeof(IPV4Hdr));
     memset(&tcph, 0, sizeof(TCPHdr));
 
@@ -743,7 +743,7 @@ static int FlagsTestParse07 (void) {
     TCPHdr tcph;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&ipv4h, 0, sizeof(IPV4Hdr));
     memset(&tcph, 0, sizeof(TCPHdr));
 
@@ -793,7 +793,7 @@ static int FlagsTestParse08 (void) {
     TCPHdr tcph;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&ipv4h, 0, sizeof(IPV4Hdr));
     memset(&tcph, 0, sizeof(TCPHdr));
 
@@ -843,7 +843,7 @@ static int FlagsTestParse09 (void) {
     TCPHdr tcph;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&ipv4h, 0, sizeof(IPV4Hdr));
     memset(&tcph, 0, sizeof(TCPHdr));
 
@@ -893,7 +893,7 @@ static int FlagsTestParse10 (void) {
     TCPHdr tcph;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&ipv4h, 0, sizeof(IPV4Hdr));
     memset(&tcph, 0, sizeof(TCPHdr));
 
@@ -943,7 +943,7 @@ static int FlagsTestParse11 (void) {
     TCPHdr tcph;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&ipv4h, 0, sizeof(IPV4Hdr));
     memset(&tcph, 0, sizeof(TCPHdr));
 
@@ -993,7 +993,7 @@ static int FlagsTestParse12 (void) {
     TCPHdr tcph;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&ipv4h, 0, sizeof(IPV4Hdr));
     memset(&tcph, 0, sizeof(TCPHdr));
 
diff --git a/src/detect-flowbits.c b/src/detect-flowbits.c
index 81d89aa..1fb8462 100644
--- a/src/detect-flowbits.c
+++ b/src/detect-flowbits.c
@@ -713,7 +713,7 @@ static int FlowBitsTestSig06(void) {
     int result = 0;
     int idx = 0;
 
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&th_v, 0, sizeof(th_v));
     memset(&f, 0, sizeof(Flow));
     memset(&flowvar, 0, sizeof(GenericVar));
@@ -810,7 +810,7 @@ static int FlowBitsTestSig07(void) {
     int result = 0;
     int idx = 0;
 
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&th_v, 0, sizeof(th_v));
     memset(&f, 0, sizeof(Flow));
     memset(&flowvar, 0, sizeof(GenericVar));
@@ -912,7 +912,7 @@ static int FlowBitsTestSig08(void) {
     int result = 0;
     int idx = 0;
 
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&th_v, 0, sizeof(th_v));
     memset(&f, 0, sizeof(Flow));
     memset(&flowvar, 0, sizeof(GenericVar));
diff --git a/src/detect-flowint.c b/src/detect-flowint.c
index e77b3e8..435cb3f 100644
--- a/src/detect-flowint.c
+++ b/src/detect-flowint.c
@@ -1412,7 +1412,7 @@ int DetectFlowintTestPacket01Real()
 
     /* Decode the packets, and test the matches*/
     for (i = 0;i < 11;i++) {
-        memset(&p, 0, sizeof(Packet));
+        memset(&p, 0, SIZE_OF_PACKET);
         DecodeEthernet(&th_v, &dtv, &p, pkts[i], pktssizes[i], NULL);
 
         SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
@@ -1749,7 +1749,7 @@ int DetectFlowintTestPacket02Real()
 
     /* Decode the packets, and test the matches*/
     for (i = 0;i < 11;i++) {
-        memset(&p, 0, sizeof(Packet));
+        memset(&p, 0, SIZE_OF_PACKET);
         DecodeEthernet(&th_v, &dtv, &p, pkts[i], pktssizes[i], NULL);
 
         SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
@@ -2082,7 +2082,7 @@ int DetectFlowintTestPacket03Real()
 
     /* Decode the packets, and test the matches*/
     for (i = 0;i < 11;i++) {
-        memset(&p, 0, sizeof(Packet));
+        memset(&p, 0, SIZE_OF_PACKET);
         DecodeEthernet(&th_v, &dtv, &p, pkts[i], pktssizes[i], NULL);
 
         SigMatchSignatures(&th_v, de_ctx, det_ctx, &p);
diff --git a/src/detect-fragbits.c b/src/detect-fragbits.c
index 517c8b5..5961974 100644
--- a/src/detect-fragbits.c
+++ b/src/detect-fragbits.c
@@ -402,7 +402,7 @@ static int FragBitsTestParse03 (void) {
     SigMatch *sm = NULL;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ipv4h, 0, sizeof(IPV4Hdr));
     AlpProtoFinalize2Thread(&dtv.udp_dp_ctx);
@@ -494,7 +494,7 @@ static int FragBitsTestParse04 (void) {
     SigMatch *sm = NULL;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&ipv4h, 0, sizeof(IPV4Hdr));
     AlpProtoFinalize2Thread(&dtv.udp_dp_ctx);
diff --git a/src/detect-fragoffset.c b/src/detect-fragoffset.c
index ba6d8a3..93086d6 100644
--- a/src/detect-fragoffset.c
+++ b/src/detect-fragoffset.c
@@ -300,7 +300,7 @@ int DetectFragOffsetMatchTest01 (void) {
     DetectEngineThreadCtx *det_ctx = NULL;
     IPV4Hdr ip4h;
 
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&ip4h, 0, sizeof(IPV4Hdr));
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&th_v, 0, sizeof(ThreadVars));
diff --git a/src/detect-icmp-id.c b/src/detect-icmp-id.c
index 31bb969..4bed9c5 100644
--- a/src/detect-icmp-id.c
+++ b/src/detect-icmp-id.c
@@ -405,7 +405,7 @@ int DetectIcmpIdMatchTest02 (void) {
     DetectEngineThreadCtx *det_ctx = NULL;
     IPV4Hdr ip4h;
 
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&ip4h, 0, sizeof(IPV4Hdr));
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&th_v, 0, sizeof(ThreadVars));
diff --git a/src/detect-ipopts.c b/src/detect-ipopts.c
index d50c3b2..b05edfa 100644
--- a/src/detect-ipopts.c
+++ b/src/detect-ipopts.c
@@ -274,7 +274,7 @@ int IpOptsTestParse03 (void) {
     IPV4Hdr ip4h;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&ip4h, 0, sizeof(IPV4Hdr));
 
     p.ip4h = &ip4h;
@@ -320,7 +320,7 @@ int IpOptsTestParse04 (void) {
     IPV4Hdr ip4h;
 
     memset(&tv, 0, sizeof(ThreadVars));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&ip4h, 0, sizeof(IPV4Hdr));
 
     p.ip4h = &ip4h;
diff --git a/src/detect-stream_size.c b/src/detect-stream_size.c
index ea3ff05..228e2ad 100644
--- a/src/detect-stream_size.c
+++ b/src/detect-stream_size.c
@@ -407,7 +407,7 @@ static int DetectStreamSizeParseTest03 (void) {
     memset(&ssn, 0, sizeof(TcpSession));
     memset(&tv, 0, sizeof(ThreadVars));
     memset(&dtx, 0, sizeof(DetectEngineThreadCtx));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&s, 0, sizeof(Signature));
     memset(&sm, 0, sizeof(SigMatch));
     memset(&client, 0, sizeof(TcpStream));
@@ -476,7 +476,7 @@ static int DetectStreamSizeParseTest04 (void) {
     memset(&ssn, 0, sizeof(TcpSession));
     memset(&tv, 0, sizeof(ThreadVars));
     memset(&dtx, 0, sizeof(DetectEngineThreadCtx));
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&s, 0, sizeof(Signature));
     memset(&sm, 0, sizeof(SigMatch));
     memset(&client, 0, sizeof(TcpStream));
diff --git a/src/detect.c b/src/detect.c
index 215b314..2f3ddf4 100644
--- a/src/detect.c
+++ b/src/detect.c
@@ -5479,8 +5479,8 @@ int SigTest24IPV4Keyword(void)
     uint16_t buflen = strlen((char *)buf);
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
-    memset(&p2, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
+    memset(&p2, 0, SIZE_OF_PACKET);
     p1.ip4c.comp_csum = -1;
     p2.ip4c.comp_csum = -1;
 
@@ -5574,8 +5574,8 @@ int SigTest25NegativeIPV4Keyword(void)
     uint16_t buflen = strlen((char *)buf);
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
-    memset(&p2, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
+    memset(&p2, 0, SIZE_OF_PACKET);
     p1.ip4c.comp_csum = -1;
     p2.ip4c.comp_csum = -1;
 
@@ -5676,8 +5676,8 @@ int SigTest26TCPV4Keyword(void)
     uint16_t buflen = strlen((char *)buf);
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
-    memset(&p2, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
+    memset(&p2, 0, SIZE_OF_PACKET);
 
     p1.tcpc.comp_csum = -1;
     p1.ip4h = (IPV4Hdr *)raw_ipv4;
@@ -5780,8 +5780,8 @@ int SigTest27NegativeTCPV4Keyword(void)
     uint16_t buflen = strlen((char *)buf);
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
-    memset(&p2, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
+    memset(&p2, 0, SIZE_OF_PACKET);
 
     p1.tcpc.comp_csum = -1;
     p1.ip4h = (IPV4Hdr *)raw_ipv4;
@@ -5894,8 +5894,8 @@ int SigTest28TCPV6Keyword(void)
                     "\r\n\r\n";
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
-    memset(&p2, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
+    memset(&p2, 0, SIZE_OF_PACKET);
 
     p1.tcpc.comp_csum = -1;
     p1.ip6h = (IPV6Hdr *)(valid_raw_ipv6 + 14);
@@ -6007,8 +6007,8 @@ int SigTest29NegativeTCPV6Keyword(void)
                     "\r\n\r\n";
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
-    memset(&p2, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
+    memset(&p2, 0, SIZE_OF_PACKET);
 
     p1.tcpc.comp_csum = -1;
     p1.ip6h = (IPV6Hdr *)(valid_raw_ipv6 + 14);
@@ -6126,8 +6126,8 @@ int SigTest30UDPV4Keyword(void)
                     "\r\n\r\nyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
-    memset(&p2, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
+    memset(&p2, 0, SIZE_OF_PACKET);
 
     p1.udpc.comp_csum = -1;
     p1.ip4h = (IPV4Hdr *)raw_ipv4;
@@ -6243,8 +6243,8 @@ int SigTest31NegativeUDPV4Keyword(void)
                     "\r\n\r\nyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
-    memset(&p2, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
+    memset(&p2, 0, SIZE_OF_PACKET);
 
     p1.udpc.comp_csum = -1;
     p1.ip4h = (IPV4Hdr *)raw_ipv4;
@@ -6354,8 +6354,8 @@ int SigTest32UDPV6Keyword(void)
                     "\r\n\r\n";
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
-    memset(&p2, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
+    memset(&p2, 0, SIZE_OF_PACKET);
 
     p1.udpc.comp_csum = -1;
     p1.ip6h = (IPV6Hdr *)(valid_raw_ipv6 + 14);
@@ -6463,8 +6463,8 @@ int SigTest33NegativeUDPV6Keyword(void)
                     "\r\n\r\n";
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
-    memset(&p2, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
+    memset(&p2, 0, SIZE_OF_PACKET);
 
     p1.udpc.comp_csum = -1;
     p1.ip6h = (IPV6Hdr *)(valid_raw_ipv6 + 14);
@@ -6575,8 +6575,8 @@ int SigTest34ICMPV4Keyword(void)
     uint16_t buflen = strlen((char *)buf);
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
-    memset(&p2, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
+    memset(&p2, 0, SIZE_OF_PACKET);
 
     p1.icmpv4c.comp_csum = -1;
     p1.ip4h = (IPV4Hdr *)(valid_raw_ipv4);
@@ -6685,8 +6685,8 @@ int SigTest35NegativeICMPV4Keyword(void)
     uint16_t buflen = strlen((char *)buf);
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
-    memset(&p2, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
+    memset(&p2, 0, SIZE_OF_PACKET);
 
     p1.icmpv4c.comp_csum = -1;
     p1.ip4h = (IPV4Hdr *)(valid_raw_ipv4);
@@ -6808,8 +6808,8 @@ int SigTest36ICMPV6Keyword(void)
     uint16_t buflen = strlen((char *)buf);
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
-    memset(&p2, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
+    memset(&p2, 0, SIZE_OF_PACKET);
 
     p1.icmpv6c.comp_csum = -1;
     p1.ip6h = (IPV6Hdr *)(valid_raw_ipv6 + 14);
@@ -6930,8 +6930,8 @@ int SigTest37NegativeICMPV6Keyword(void)
     uint16_t buflen = strlen((char *)buf);
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
-    memset(&p2, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
+    memset(&p2, 0, SIZE_OF_PACKET);
 
     p1.icmpv6c.comp_csum = -1;
     p1.ip6h = (IPV6Hdr *)(valid_raw_ipv6 + 14);
@@ -7045,14 +7045,18 @@ int SigTest38Real(int mpm_type)
     uint16_t buflen = sizeof(buf);
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
 
     /* Copy raw data into packet */
-    memcpy(&p1.pkt, raw_eth, ethlen);
-    memcpy(p1.pkt + ethlen, raw_ipv4, ipv4len);
-    memcpy(p1.pkt + ethlen + ipv4len, raw_tcp, tcplen);
-    memcpy(p1.pkt + ethlen + ipv4len + tcplen, buf, buflen);
-    p1.pktlen = ethlen + ipv4len + tcplen + buflen;
+    if (PacketCopyData(&p1, raw_eth, ethlen) == -1)
+        return 1;
+    if (PacketCopyDataOffset(&p1, ethlen, raw_ipv4, ipv4len) == -1)
+        return 1;
+    if (PacketCopyDataOffset(&p1, ethlen + ipv4len, raw_tcp, tcplen) == -1)
+        return 1;
+    if (PacketCopyDataOffset(&p1, ethlen + ipv4len + tcplen, buf, buflen) == -1)
+        return 1;
+    SET_PKT_LEN(&p1, ethlen + ipv4len + tcplen + buflen);
 
     p1.tcpc.comp_csum = -1;
     p1.ethh = (EthernetHdr *)raw_eth;
@@ -7061,7 +7065,7 @@ int SigTest38Real(int mpm_type)
     p1.tcpvars.hlen = 0;
     p1.src.family = AF_INET;
     p1.dst.family = AF_INET;
-    p1.payload = p1.pkt + ethlen + ipv4len + tcplen;
+    p1.payload = GET_PKT_DATA(&p1) + ethlen + ipv4len + tcplen;
     p1.payload_len = buflen;
     p1.proto = IPPROTO_TCP;
 
@@ -7172,14 +7176,18 @@ int SigTest39Real(int mpm_type)
     uint16_t buflen = sizeof(buf);
 
     memset(&th_v, 0, sizeof(ThreadVars));
-    memset(&p1, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
 
     /* Copy raw data into packet */
-    memcpy(&p1.pkt, raw_eth, ethlen);
-    memcpy(p1.pkt + ethlen, raw_ipv4, ipv4len);
-    memcpy(p1.pkt + ethlen + ipv4len, raw_tcp, tcplen);
-    memcpy(p1.pkt + ethlen + ipv4len + tcplen, buf, buflen);
-    p1.pktlen = ethlen + ipv4len + tcplen + buflen;
+    if (PacketCopyData(&p1, raw_eth, ethlen) == -1)
+        return 1;
+    if (PacketCopyDataOffset(&p1, ethlen, raw_ipv4, ipv4len) == -1)
+        return 1;
+    if (PacketCopyDataOffset(&p1, ethlen + ipv4len, raw_tcp, tcplen) == -1)
+        return 1;
+    if (PacketCopyDataOffset(&p1, ethlen + ipv4len + tcplen, buf, buflen) == -1)
+        return 1;
+    SET_PKT_LEN(&p1, ethlen + ipv4len + tcplen + buflen);
 
     p1.tcpc.comp_csum = -1;
     p1.ethh = (EthernetHdr *)raw_eth;
@@ -7188,7 +7196,7 @@ int SigTest39Real(int mpm_type)
     p1.tcpvars.hlen = 0;
     p1.src.family = AF_INET;
     p1.dst.family = AF_INET;
-    p1.payload = p1.pkt + ethlen + ipv4len + tcplen;
+    p1.payload = GET_PKT_DATA(&p1) + ethlen + ipv4len + tcplen;
     p1.payload_len = buflen;
     p1.proto = IPPROTO_TCP;
 
@@ -7313,7 +7321,7 @@ int SigTest36ContentAndIsdataatKeywords01Real (int mpm_type) {
     ThreadVars th_v;
     DetectEngineThreadCtx *det_ctx = NULL;
 
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&th_v, 0, sizeof(th_v));
 
@@ -7426,7 +7434,7 @@ int SigTest37ContentAndIsdataatKeywords02Real (int mpm_type) {
     ThreadVars th_v;
     DetectEngineThreadCtx *det_ctx = NULL;
 
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&th_v, 0, sizeof(th_v));
 
@@ -9024,7 +9032,7 @@ static int SigTestWithinReal01 (int mpm_type) {
 
     /* packet 1 */
     Packet p1;
-    memset(&p1, 0, sizeof(Packet));
+    memset(&p1, 0, SIZE_OF_PACKET);
     DecodeEthernet(&th_v, &dtv, &p1, rawpkt1, sizeof(rawpkt1), NULL);
     SigMatchSignatures(&th_v, de_ctx, det_ctx, &p1);
     if (!(PacketAlertCheck(&p1, 556))) {
@@ -9034,7 +9042,7 @@ static int SigTestWithinReal01 (int mpm_type) {
 
     /* packet 2 */
     Packet p2;
-    memset(&p2, 0, sizeof(Packet));
+    memset(&p2, 0, SIZE_OF_PACKET);
     DecodeEthernet(&th_v, &dtv, &p2, rawpkt2, sizeof(rawpkt2), NULL);
     SigMatchSignatures(&th_v, de_ctx, det_ctx, &p2);
     if (!(PacketAlertCheck(&p2, 556))) {
@@ -9044,7 +9052,7 @@ static int SigTestWithinReal01 (int mpm_type) {
 
     /* packet 3 */
     Packet p3;
-    memset(&p3, 0, sizeof(Packet));
+    memset(&p3, 0, SIZE_OF_PACKET);
     DecodeEthernet(&th_v, &dtv, &p3, rawpkt3, sizeof(rawpkt3), NULL);
     SigMatchSignatures(&th_v, de_ctx, det_ctx, &p3);
     if (!(PacketAlertCheck(&p3, 556))) {
@@ -9054,7 +9062,7 @@ static int SigTestWithinReal01 (int mpm_type) {
 
     /* packet 4 */
     Packet p4;
-    memset(&p4, 0, sizeof(Packet));
+    memset(&p4, 0, SIZE_OF_PACKET);
     DecodeEthernet(&th_v, &dtv, &p4, rawpkt4, sizeof(rawpkt4), NULL);
     SigMatchSignatures(&th_v, de_ctx, det_ctx, &p4);
     if (!(PacketAlertCheck(&p4, 556))) {
diff --git a/src/flow.c b/src/flow.c
index d955529..cdc9d88 100644
--- a/src/flow.c
+++ b/src/flow.c
@@ -706,7 +706,7 @@ void FlowHandlePacket (ThreadVars *tv, Packet *p)
         f->tosrcpktcnt++;
         p->flowflags |= FLOW_PKT_TOCLIENT;
     }
-    f->bytecnt += p->pktlen;
+    f->bytecnt += GET_PKT_LEN(p);
 
     if (f->flags & FLOW_TO_DST_SEEN && f->flags & FLOW_TO_SRC_SEEN) {
         SCLogDebug("pkt %p FLOW_PKT_ESTABLISHED", p);
diff --git a/src/source-erf-dag.c b/src/source-erf-dag.c
index 44a11c7..422d9e8 100644
--- a/src/source-erf-dag.c
+++ b/src/source-erf-dag.c
@@ -521,16 +521,17 @@ TmEcode ProcessErfDagRecord(ErfDagThreadVars *ewtn, char *prec, Packet *p)
 
     pload = &(dr->rec);
 
-    p->pktlen = wlen - 4;   /* Trim the FCS... */
+    SET_PKT_LEN(p, wlen - 4);   /* Trim the FCS... */
     p->datalink = LINKTYPE_ETHERNET;
 
     /* Take into account for link type Ethernet ETH frame starts
      * after ther ERF header + pad.
      */
-    memcpy(p->pkt, pload->eth.dst, p->pktlen);
+    if (PacketCopyData(p, pload->eth.dst, GET_PKT_LEN(p)) == -1)
+        SCReturnInt(TM_ECODE_FAILED);
 
-    SCLogDebug("p->pktlen: %" PRIu32 " (pkt %02x, p->pkt %02x)",
-               p->pktlen, *p, *p->pkt);
+    SCLogDebug("pktlen: %" PRIu32 " (pkt %02x, pkt data %02x)",
+               GET_PKT_LEN(p), *p, *GET_PKT_DATA(p));
 
     /* Convert ERF time to timeval - from libpcap. */
     uint64_t ts = dr->ts;
@@ -609,18 +610,18 @@ TmEcode DecodeErfDag(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq,
     SCPerfCounterIncr(dtv->counter_pkts, tv->sc_perf_pca);
     SCPerfCounterIncr(dtv->counter_pkts_per_sec, tv->sc_perf_pca);
 
-    SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, p->pktlen);
-    SCPerfCounterAddDouble(dtv->counter_bytes_per_sec, tv->sc_perf_pca, p->pktlen);
+    SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, GET_PKT_LEN(p));
+    SCPerfCounterAddDouble(dtv->counter_bytes_per_sec, tv->sc_perf_pca, GET_PKT_LEN(p));
     SCPerfCounterAddDouble(dtv->counter_mbit_per_sec, tv->sc_perf_pca,
-                           (p->pktlen * 8)/1000000.0);
+                           (GET_PKT_LEN(p) * 8)/1000000.0);
 
-    SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, p->pktlen);
-    SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, p->pktlen);
+    SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));
+    SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));
 
         /* call the decoder */
     switch(p->datalink) {
         case LINKTYPE_ETHERNET:
-            DecodeEthernet(tv, dtv, p, p->pkt, p->pktlen, pq);
+            DecodeEthernet(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq);
             break;
         default:
             SCLogError(SC_ERR_DATALINK_UNIMPLEMENTED,
diff --git a/src/source-erf-file.c b/src/source-erf-file.c
index f8462c0..9c675f8 100644
--- a/src/source-erf-file.c
+++ b/src/source-erf-file.c
@@ -120,7 +120,7 @@ ReceiveErfFile(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQue
     }
     int rlen = ntohs(dr.rlen);
     int wlen = ntohs(dr.wlen);
-    r = fread(p->pkt, rlen - sizeof(DagRecord), 1, etv->erf);
+    r = fread(GET_PKT_DATA(p), rlen - sizeof(DagRecord), 1, etv->erf);
     if (r < 1) {
         SCLogInfo("End of ERF file reached or an error occurred.");
         EngineStop();
@@ -134,7 +134,7 @@ ReceiveErfFile(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQue
         SCReturnInt(TM_ECODE_FAILED);
     }
 
-    p->pktlen = wlen - 4; /* Trim the FCS... */
+    GET_PKT_LEN(p) = wlen - 4; /* Trim the FCS... */
     p->datalink = LINKTYPE_ETHERNET;
 
     /* Convert ERF time to timeval - from libpcap. */
@@ -227,15 +227,15 @@ DecodeErfFile(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQueu
     SCPerfCounterIncr(dtv->counter_pkts, tv->sc_perf_pca);
     SCPerfCounterIncr(dtv->counter_pkts_per_sec, tv->sc_perf_pca);
 
-    SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, p->pktlen);
-    SCPerfCounterAddDouble(dtv->counter_bytes_per_sec, tv->sc_perf_pca, p->pktlen);
+    SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, GET_PKT_LEN(p));
+    SCPerfCounterAddDouble(dtv->counter_bytes_per_sec, tv->sc_perf_pca, GET_PKT_LEN(p));
     SCPerfCounterAddDouble(dtv->counter_mbit_per_sec, tv->sc_perf_pca,
-                           (p->pktlen * 8)/1000000.0 );
+                           (GET_PKT_LEN(p) * 8)/1000000.0 );
 
-    SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, p->pktlen);
-    SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, p->pktlen);
+    SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));
+    SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));
 
-    DecodeEthernet(tv, dtv, p, p->pkt, p->pktlen, pq);
+    DecodeEthernet(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq);
 
     SCReturnInt(TM_ECODE_OK);
 }
diff --git a/src/source-ipfw.c b/src/source-ipfw.c
index 8515085..93b19fe 100644
--- a/src/source-ipfw.c
+++ b/src/source-ipfw.c
@@ -254,9 +254,9 @@ TmEcode ReceiveIPFW(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Pack
     ptv->bytes += pktlen;
 
     p->datalink = ptv->datalink;
-    p->pktlen = pktlen;
-    memcpy(p->pkt, pkt, p->pktlen);
-    SCLogDebug("Packet info: p->pktlen: %" PRIu32 " (pkt %02x, p->pkt %02x)", p->pktlen, *pkt, *p->pkt);
+    if (PacketCopyData(p, pkt, pktlen) == -1)
+        SCReturnInt(TM_ECODE_FAILED);
+    SCLogDebug("Packet info: pkt_len: %" PRIu32 " (pkt %02x, pkt_data %02x)", GET_PKT_LEN(p), *pkt, GET_PKT_DATA(p));
 
     /* pass on... */
     tv->tmqh_out(tv, p);
@@ -401,30 +401,30 @@ TmEcode ReceiveIPFWThreadDeinit(ThreadVars *tv, void *data) {
  */
 TmEcode DecodeIPFW(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQueue *postpq)
 {
-    IPV4Hdr *ip4h = (IPV4Hdr *)p->pkt;
-    IPV6Hdr *ip6h = (IPV6Hdr *)p->pkt;
+    IPV4Hdr *ip4h = (IPV4Hdr *)GET_PKT_DATA(p);
+    IPV6Hdr *ip6h = (IPV6Hdr *)GET_PKT_DATA(p);
     DecodeThreadVars *dtv = (DecodeThreadVars *)data;
 
     SCEnter();
 
     /* update counters */
     SCPerfCounterIncr(dtv->counter_pkts, tv->sc_perf_pca);
-    SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, p->pktlen);
-    SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, p->pktlen);
-    SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, p->pktlen);
+    SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, GET_PKT_LEN(p));
+    SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));
+    SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));
 
     /* Process IP packets */
     if (IPV4_GET_RAW_VER(ip4h) == 4) {
         SCLogDebug("DecodeIPFW ip4 processing");
-        DecodeIPV4(tv, dtv, p, p->pkt, p->pktlen, pq);
+        DecodeIPV4(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq);
 
     } else if(IPV6_GET_RAW_VER(ip6h) == 6) {
         SCLogDebug("DecodeIPFW ip6 processing");
-        DecodeIPV6(tv, dtv, p, p->pkt, p->pktlen, pq);
+        DecodeIPV6(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq);
 
     } else {
         /* We don't support anything besides IP packets for now, bridged packets? */
-        SCLogInfo("IPFW unknown protocol support %02x", *p->pkt);
+        SCLogInfo("IPFW unknown protocol support %02x", *GET_PKT_DATA(p));
        SCReturnInt(TM_ECODE_FAILED);
     }
 
@@ -485,7 +485,7 @@ TmEcode IPFWSetVerdict(ThreadVars *tv, IPFWThreadVars *ptv, Packet *p) {
         /* For divert sockets, accepting means writing the
          * packet back to the socket for ipfw to pick up
          */
-        SCLogDebug("IPFWSetVerdict writing to socket %d, %p, %u", ipfw_sock,p->pkt,p->pktlen);
+        SCLogDebug("IPFWSetVerdict writing to socket %d, %p, %u", ipfw_sock,GET_PKT_DATA(p),GET_PKT_LEN(p));
 
 
         while ( (poll(&IPFWpoll,1,IPFW_SOCKET_POLL_MSEC)) < 1) {
@@ -498,7 +498,7 @@ TmEcode IPFWSetVerdict(ThreadVars *tv, IPFWThreadVars *ptv, Packet *p) {
         }
 
         SCMutexLock(&ipfw_socket_lock);
-        if (sendto(ipfw_sock, p->pkt, p->pktlen, 0,(struct sockaddr *)&ipfw_sin, ipfw_sinlen) == -1) {
+        if (sendto(ipfw_sock, GET_PKT_DATA(p), GET_PKT_LEN(p), 0,(struct sockaddr *)&ipfw_sin, ipfw_sinlen) == -1) {
             SCLogWarning(SC_WARN_IPFW_XMIT,"Write to ipfw divert socket failed: %s",strerror(errno));
             SCMutexUnlock(&ipfw_socket_lock);
             SCReturnInt(TM_ECODE_FAILED);
@@ -506,7 +506,7 @@ TmEcode IPFWSetVerdict(ThreadVars *tv, IPFWThreadVars *ptv, Packet *p) {
 
         SCMutexUnlock(&ipfw_socket_lock);
 
-        SCLogDebug("Sent Packet back into IPFW Len: %d",p->pktlen);
+        SCLogDebug("Sent Packet back into IPFW Len: %d",GET_PKT_LEN(p));
 
     } /* end IPFW_ACCEPT */
 
diff --git a/src/source-nfq.c b/src/source-nfq.c
index 4e90bb8..d31d2b7 100644
--- a/src/source-nfq.c
+++ b/src/source-nfq.c
@@ -177,15 +177,18 @@ void NFQSetupPkt (Packet *p, void *data)
              * to trigger an error in packet decoding.
              * This is unlikely to happen */
             SCLogWarning(SC_ERR_INVALID_ARGUMENTS, "NFQ sent too big packet");
-            p->pktlen = 0;
+            SET_PKT_LEN(p, 0);
         } else {
-            memcpy(p->pkt, pktdata, ret);
-            p->pktlen = (size_t)ret;
+            ret = PacketCopyData(p, (uint8_t *)pktdata, ret);
+            if (ret == -1) {
+                SCLogWarning(SC_ERR_INVALID_ARGUMENTS, "NFQ send strange packet");
+                SET_PKT_LEN(p, 0);
+            }
         }
     } else if (ret ==  -1) {
         /* unable to get pointer to data, ensure packet length is zero.
          * This will trigger an error in packet decoding */
-        p->pktlen = 0;
+        SET_PKT_LEN(p, 0);
     }
 
     ret = nfq_get_timestamp(tb, &p->ts);
@@ -214,7 +217,7 @@ static int NFQCallBack(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg,
 
 #ifdef COUNTERS
     nfq_t->pkts++;
-    nfq_t->bytes += p->pktlen;
+    nfq_t->bytes += GET_PKT_LEN(p);
 #endif /* COUNTERS */
 
     /* pass on... */
@@ -616,22 +619,22 @@ TmEcode DecodeNFQ(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Packet
     DecodeThreadVars *dtv = (DecodeThreadVars *)data;
 
     SCPerfCounterIncr(dtv->counter_pkts, tv->sc_perf_pca);
-    SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, p->pktlen);
-    SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, p->pktlen);
-    SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, p->pktlen);
-    SCPerfCounterAddDouble(dtv->counter_bytes_per_sec, tv->sc_perf_pca, p->pktlen);
+    SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, GET_PKT_LEN(p));
+    SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));
+    SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));
+    SCPerfCounterAddDouble(dtv->counter_bytes_per_sec, tv->sc_perf_pca, GET_PKT_LEN(p));
     SCPerfCounterAddDouble(dtv->counter_mbit_per_sec, tv->sc_perf_pca,
-                           (p->pktlen * 8)/1000000.0);
+                           (GET_PKT_LEN(p) * 8)/1000000.0);
 
     if (IPV4_GET_RAW_VER(ip4h) == 4) {
         SCLogDebug("IPv4 packet");
 
-        DecodeIPV4(tv, dtv, p, p->pkt, p->pktlen, pq);
+        DecodeIPV4(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq);
     } else if(IPV6_GET_RAW_VER(ip6h) == 6) {
         SCLogDebug("IPv6 packet");
-        DecodeIPV6(tv, dtv, p, p->pkt, p->pktlen, pq);
+        DecodeIPV6(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq);
     } else {
-        SCLogDebug("packet unsupported by NFQ, first byte: %02x", *p->pkt);
+        SCLogDebug("packet unsupported by NFQ, first byte: %02x", *GET_PKT_DATA(p));
     }
 
     return TM_ECODE_OK;
diff --git a/src/source-pcap-file.c b/src/source-pcap-file.c
index 0575d52..4d278c1 100644
--- a/src/source-pcap-file.c
+++ b/src/source-pcap-file.c
@@ -135,9 +135,9 @@ void PcapFileCallback(char *user, struct pcap_pkthdr *h, u_char *pkt) {
     ptv->pkts++;
     ptv->bytes += h->caplen;
 
-    p->pktlen = h->caplen;
-    memcpy(p->pkt, pkt, p->pktlen);
-    //printf("PcapFileCallback: p->pktlen: %" PRIu32 " (pkt %02x, p->pkt %02x)\n", p->pktlen, *pkt, *p->pkt);
+    if (PacketCopyData(p, pkt, h->caplen))
+        SCReturn;
+    //printf("PcapFileCallback: p->pktlen: %" PRIu32 " (pkt %02x, p->pkt %02x)\n", GET_PKT_LEN(p), *pkt, *GET_PKT_DATA(p));
 
     /* store the packet in our array */
     ptv->array[ptv->array_idx] = p;
@@ -309,16 +309,16 @@ TmEcode DecodePcapFile(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, P
     SCPerfCounterIncr(dtv->counter_pkts, tv->sc_perf_pca);
     SCPerfCounterIncr(dtv->counter_pkts_per_sec, tv->sc_perf_pca);
 
-    SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, p->pktlen);
-    SCPerfCounterAddDouble(dtv->counter_bytes_per_sec, tv->sc_perf_pca, p->pktlen);
+    SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, GET_PKT_LEN(p));
+    SCPerfCounterAddDouble(dtv->counter_bytes_per_sec, tv->sc_perf_pca, GET_PKT_LEN(p));
     SCPerfCounterAddDouble(dtv->counter_mbit_per_sec, tv->sc_perf_pca,
-                           (p->pktlen * 8)/1000000.0 );
+                           (GET_PKT_LEN(p) * 8)/1000000.0 );
 
-    SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, p->pktlen);
-    SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, p->pktlen);
+    SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));
+    SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));
 
     /* call the decoder */
-    pcap_g.Decoder(tv, dtv, p, p->pkt, p->pktlen, pq);
+    pcap_g.Decoder(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq);
 
     SCReturnInt(TM_ECODE_OK);
 }
diff --git a/src/source-pcap.c b/src/source-pcap.c
index bbf92d8..c3ab809 100644
--- a/src/source-pcap.c
+++ b/src/source-pcap.c
@@ -151,9 +151,11 @@ void PcapCallback(char *user, struct pcap_pkthdr *h, u_char *pkt) {
     ptv->bytes += h->caplen;
 
     p->datalink = ptv->datalink;
-    p->pktlen = h->caplen;
-    memcpy(p->pkt, pkt, p->pktlen);
-    SCLogDebug("p->pktlen: %" PRIu32 " (pkt %02x, p->pkt %02x)", p->pktlen, *pkt, *p->pkt);
+    SET_PKT_LEN(p, h->caplen);
+    if (PacketCopyData(p, pkt, GET_PKT_LEN(p)) == -1)
+        SCReturn;
+    SCLogDebug("pktlen: %" PRIu32 " (pkt %02x, pkt data %02x)",
+               GET_PKT_LEN(p), *pkt, *GET_PKT_DATA(p));
 
     /* store the packet in our array */
     ptv->array[ptv->array_idx] = p;
@@ -472,27 +474,27 @@ TmEcode DecodePcap(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Packe
     SCPerfCounterIncr(dtv->counter_pkts, tv->sc_perf_pca);
     SCPerfCounterIncr(dtv->counter_pkts_per_sec, tv->sc_perf_pca);
 
-    SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, p->pktlen);
-    SCPerfCounterAddDouble(dtv->counter_bytes_per_sec, tv->sc_perf_pca, p->pktlen);
+    SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, GET_PKT_LEN(p));
+    SCPerfCounterAddDouble(dtv->counter_bytes_per_sec, tv->sc_perf_pca, GET_PKT_LEN(p));
     SCPerfCounterAddDouble(dtv->counter_mbit_per_sec, tv->sc_perf_pca,
-                           (p->pktlen * 8)/1000000.0);
+                           (GET_PKT_LEN(p) * 8)/1000000.0);
 
-    SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, p->pktlen);
-    SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, p->pktlen);
+    SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));
+    SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));
 
     /* call the decoder */
     switch(p->datalink) {
         case LINKTYPE_LINUX_SLL:
-            DecodeSll(tv, dtv, p, p->pkt, p->pktlen, pq);
+            DecodeSll(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq);
             break;
         case LINKTYPE_ETHERNET:
-            DecodeEthernet(tv, dtv, p,p->pkt, p->pktlen, pq);
+            DecodeEthernet(tv, dtv, p,GET_PKT_DATA(p), GET_PKT_LEN(p), pq);
             break;
         case LINKTYPE_PPP:
-            DecodePPP(tv, dtv, p, p->pkt, p->pktlen, pq);
+            DecodePPP(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq);
             break;
         case LINKTYPE_RAW:
-            DecodeRaw(tv, dtv, p, p->pkt, p->pktlen, pq);
+            DecodeRaw(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq);
             break;
         default:
             SCLogError(SC_ERR_DATALINK_UNIMPLEMENTED, "Error: datalink type %" PRId32 " not yet supported in module DecodePcap", p->datalink);
diff --git a/src/source-pfring.c b/src/source-pfring.c
index bcbec88..d50bdfd 100644
--- a/src/source-pfring.c
+++ b/src/source-pfring.c
@@ -171,8 +171,8 @@ void PfringProcessPacket(void *user, struct pfring_pkthdr *h, u_char *pkt, Packe
     /* PF_RING all packets are marked as a link type of ethernet so that is what we do here.  */
     p->datalink = LINKTYPE_ETHERNET;
 
-    p->pktlen = h->caplen;
-    memcpy(p->pkt, pkt, p->pktlen);
+    if (PacketCopyData(p, pkt, h->caplen) == -1)
+        SCLogError(SC_ERR_MEM_ALLOC, "PF_RING process packet failed: %s", strerror(errno));
 
 }
 
@@ -354,15 +354,15 @@ TmEcode DecodePfring(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Pac
     SCPerfCounterIncr(dtv->counter_pkts, tv->sc_perf_pca);
     SCPerfCounterIncr(dtv->counter_pkts_per_sec, tv->sc_perf_pca);
 
-    SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, p->pktlen);
-    SCPerfCounterAddDouble(dtv->counter_bytes_per_sec, tv->sc_perf_pca, p->pktlen);
+    SCPerfCounterAddUI64(dtv->counter_bytes, tv->sc_perf_pca, GET_PKT_LEN(p));
+    SCPerfCounterAddDouble(dtv->counter_bytes_per_sec, tv->sc_perf_pca, GET_PKT_LEN(p));
     SCPerfCounterAddDouble(dtv->counter_mbit_per_sec, tv->sc_perf_pca,
-                           (p->pktlen * 8)/1000000.0 );
+                           (GET_PKT_LEN(p) * 8)/1000000.0 );
 
-    SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, p->pktlen);
-    SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, p->pktlen);
+    SCPerfCounterAddUI64(dtv->counter_avg_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));
+    SCPerfCounterSetUI64(dtv->counter_max_pkt_size, tv->sc_perf_pca, GET_PKT_LEN(p));
 
-    DecodeEthernet(tv, dtv, p,p->pkt, p->pktlen, pq);
+    DecodeEthernet(tv, dtv, p,GET_PKT_DATA(p), GET_PKT_LEN(p), pq);
 
     return TM_ECODE_OK;
 }
diff --git a/src/stream-tcp.c b/src/stream-tcp.c
index 184c69c..a6fc879 100644
--- a/src/stream-tcp.c
+++ b/src/stream-tcp.c
@@ -3242,7 +3242,7 @@ void StreamTcpSetSessionNoApplayerInspectionFlag (TcpSession *ssn)
 static int StreamTcpTest01 (void) {
     Packet p;
     Flow f;
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     p.flow = &f;
     int ret = 0;
@@ -3292,7 +3292,7 @@ static int StreamTcpTest02 (void) {
     StreamMsgQueue stream_q;
     memset(&stream_q, 0, sizeof(StreamMsgQueue));
     memset(&ra_ctx, 0, sizeof(TcpReassemblyThreadCtx));
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -3380,7 +3380,7 @@ static int StreamTcpTest03 (void) {
     ThreadVars tv;
     StreamTcpThread stt;
     TCPHdr tcph;
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -3448,7 +3448,7 @@ static int StreamTcpTest04 (void) {
     ThreadVars tv;
     StreamTcpThread stt;
     TCPHdr tcph;
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -3510,7 +3510,7 @@ static int StreamTcpTest05 (void) {
     StreamTcpThread stt;
     TCPHdr tcph;
     uint8_t payload[4];
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -3609,7 +3609,7 @@ static int StreamTcpTest06 (void) {
     ThreadVars tv;
     StreamTcpThread stt;
     TCPHdr tcph;
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&ssn, 0, sizeof (TcpSession));
     memset(&tv, 0, sizeof (ThreadVars));
@@ -3660,7 +3660,7 @@ static int StreamTcpTest07 (void) {
     TCPOpt ts;
     uint32_t data[2];
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof(StreamTcpThread));
@@ -3746,7 +3746,7 @@ static int StreamTcpTest08 (void) {
     TCPOpt ts;
     uint32_t data[2];
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof(StreamTcpThread));
@@ -3831,7 +3831,7 @@ static int StreamTcpTest09 (void) {
     TCPHdr tcph;
     uint8_t payload[1] = {0x42};
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof(StreamTcpThread));
@@ -3902,7 +3902,7 @@ static int StreamTcpTest10 (void) {
     StreamTcpThread stt;
     TCPHdr tcph;
     uint8_t payload[4];
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -3996,7 +3996,7 @@ static int StreamTcpTest11 (void) {
     StreamTcpThread stt;
     TCPHdr tcph;
     uint8_t payload[4];
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -4091,7 +4091,7 @@ static int StreamTcpTest12 (void) {
     StreamTcpThread stt;
     TCPHdr tcph;
     uint8_t payload[4];
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -4179,7 +4179,7 @@ static int StreamTcpTest13 (void) {
     StreamTcpThread stt;
     TCPHdr tcph;
     uint8_t payload[4];
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -4376,7 +4376,7 @@ static int StreamTcpTest14 (void) {
     char os_policy_name[10] = "windows";
     char *ip_addr;
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -4537,7 +4537,7 @@ static int StreamTcp4WHSTest01 (void) {
     ThreadVars tv;
     StreamTcpThread stt;
     TCPHdr tcph;
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -4611,7 +4611,7 @@ static int StreamTcp4WHSTest02 (void) {
     ThreadVars tv;
     StreamTcpThread stt;
     TCPHdr tcph;
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -4674,7 +4674,7 @@ static int StreamTcp4WHSTest03 (void) {
     ThreadVars tv;
     StreamTcpThread stt;
     TCPHdr tcph;
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -4752,7 +4752,7 @@ static int StreamTcpTest15 (void) {
     char os_policy_name[10] = "windows";
     char *ip_addr;
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -4918,7 +4918,7 @@ static int StreamTcpTest16 (void) {
     char os_policy_name[10] = "windows";
     char *ip_addr;
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -5085,7 +5085,7 @@ static int StreamTcpTest17 (void) {
     char os_policy_name[10] = "windows";
     char *ip_addr;
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -5651,7 +5651,7 @@ static int StreamTcpTest25(void) {
     TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx();
     int ret = 0;
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -5745,7 +5745,7 @@ static int StreamTcpTest26(void) {
     TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx();
     int ret = 0;
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -5833,7 +5833,7 @@ static int StreamTcpTest27(void) {
     TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx();
     int ret = 0;
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -5974,7 +5974,7 @@ static int StreamTcpTest29(void)
     TcpStream server;
     TcpStream client;
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -6117,7 +6117,7 @@ static int StreamTcpTest30(void)
     TcpStream server;
     TcpStream client;
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -6261,7 +6261,7 @@ static int StreamTcpTest31(void)
     TcpStream client;
     TCPOpt tcpopt;
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -6412,7 +6412,7 @@ static int StreamTcpTest32(void) {
     TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx();
     int ret = 0;
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -6500,7 +6500,7 @@ static int StreamTcpTest33 (void) {
     StreamMsgQueue stream_q;
     memset(&stream_q, 0, sizeof(StreamMsgQueue));
     memset(&ra_ctx, 0, sizeof(TcpReassemblyThreadCtx));
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -6599,7 +6599,7 @@ static int StreamTcpTest34 (void) {
     StreamMsgQueue stream_q;
     memset(&stream_q, 0, sizeof(StreamMsgQueue));
     memset(&ra_ctx, 0, sizeof(TcpReassemblyThreadCtx));
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -6662,7 +6662,7 @@ static int StreamTcpTest35 (void) {
     StreamMsgQueue stream_q;
     memset(&stream_q, 0, sizeof(StreamMsgQueue));
     memset(&ra_ctx, 0, sizeof(TcpReassemblyThreadCtx));
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -6723,7 +6723,7 @@ static int StreamTcpTest36(void) {
     TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx();
     int ret = 0;
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
@@ -6811,7 +6811,7 @@ static int StreamTcpTest37(void) {
     TcpReassemblyThreadCtx *ra_ctx = StreamTcpReassembleInitThreadCtx();
     int ret = 0;
 
-    memset (&p, 0, sizeof(Packet));
+    memset (&p, 0, SIZE_OF_PACKET);
     memset (&f, 0, sizeof(Flow));
     memset(&tv, 0, sizeof (ThreadVars));
     memset(&stt, 0, sizeof (StreamTcpThread));
diff --git a/src/suricata.c b/src/suricata.c
index 0b967ac..2e49ed6 100644
--- a/src/suricata.c
+++ b/src/suricata.c
@@ -1046,11 +1046,11 @@ int main(int argc, char **argv)
 #endif /* OS_WIN32 */
 
     /* pre allocate packets */
-    SCLogDebug("preallocating packets... packet size %" PRIuMAX "", (uintmax_t)sizeof(Packet));
+    SCLogDebug("preallocating packets... packet size %" PRIuMAX "", (uintmax_t)SIZE_OF_PACKET);
     int i = 0;
     for (i = 0; i < max_pending_packets; i++) {
         /* XXX pkt alloc function */
-        Packet *p = SCMalloc(sizeof(Packet));
+        Packet *p = SCMalloc(SIZE_OF_PACKET);
         if (p == NULL) {
             SCLogError(SC_ERR_FATAL, "Fatal error encountered while allocating a packet. Exiting...");
             exit(EXIT_FAILURE);
@@ -1060,7 +1060,7 @@ int main(int argc, char **argv)
         PacketPoolStorePacket(p);
     }
     SCLogInfo("preallocated %"PRIiMAX" packets. Total memory %"PRIuMAX"",
-        max_pending_packets, (uintmax_t)(max_pending_packets*sizeof(Packet)));
+        max_pending_packets, (uintmax_t)(max_pending_packets*SIZE_OF_PACKET));
 
     FlowInitConfig(FLOW_VERBOSE);
 
diff --git a/src/util-mpm-b2g-cuda.c b/src/util-mpm-b2g-cuda.c
index c92aae6..7c37d11 100644
--- a/src/util-mpm-b2g-cuda.c
+++ b/src/util-mpm-b2g-cuda.c
@@ -2337,7 +2337,7 @@ static int B2gCudaTest01(void)
     pb->packets_payload_offset_buffer[0] = 0;
 
     Packet p;
-    memset(&p, 0, sizeof(Packet));
+    memset(&p, 0, SIZE_OF_PACKET);
     pb->packets_address_buffer[0] = &p;
     p.payload_len = strlen(string);
 
@@ -2473,12 +2473,12 @@ static int B2gCudaTest02(void)
 
     memset(p, 0, sizeof(p));
     for (i = 0; i < no_of_pkts; i++) {
-        p[i] = malloc(sizeof(Packet));
+        p[i] = malloc(SIZE_OF_PACKET);
         if (p[i] == NULL) {
             printf("error allocating memory\n");
             exit(EXIT_FAILURE);
         }
-        memset(p[i], 0, sizeof(Packet));
+        memset(p[i], 0, SIZE_OF_PACKET);
         DecodeEthernet(&tv, &dtv, p[i], raw_eth, sizeof(raw_eth), NULL);
     }
 
@@ -2691,12 +2691,12 @@ static int B2gCudaTest03(void)
 
     FlowInitConfig(FLOW_QUIET);
     for (i = 0; i < no_of_pkts; i++) {
-        p[i] = malloc(sizeof(Packet));
+        p[i] = malloc(SIZE_OF_PACKET);
         if (p[i] == NULL) {
             printf("error allocating memory\n");
             exit(EXIT_FAILURE);
         }
-        memset(p[i], 0, sizeof(Packet));
+        memset(p[i], 0, SIZE_OF_PACKET);
         DecodeEthernet(&tv, &dtv, p[i], raw_eth, sizeof(raw_eth), NULL);
     }
 
diff --git a/src/util-unittest-helper.c b/src/util-unittest-helper.c
index af3610d..74a5a54 100644
--- a/src/util-unittest-helper.c
+++ b/src/util-unittest-helper.c
@@ -60,10 +60,10 @@ Packet *UTHBuildPacketIPV6Real(uint8_t *payload, uint16_t payload_len,
                            uint16_t sport, uint16_t dport) {
     uint32_t in[4];
 
-    Packet *p = SCMalloc(sizeof(Packet));
+    Packet *p = SCMalloc(SIZE_OF_PACKET);
     if (p == NULL)
         return NULL;
-    memset(p, 0, sizeof(Packet));
+    memset(p, 0, SIZE_OF_PACKET);
 
     TimeSet(&p->ts);
 
@@ -100,7 +100,7 @@ Packet *UTHBuildPacketIPV6Real(uint8_t *payload, uint16_t payload_len,
     p->tcph->th_sport = sport;
     p->tcph->th_dport = dport;
 
-    p->pktlen = sizeof(IPV6Hdr) + sizeof(TCPHdr) + payload_len;
+    SET_PKT_LEN(p, sizeof(IPV6Hdr) + sizeof(TCPHdr) + payload_len);
     return p;
 }
 
@@ -123,10 +123,11 @@ Packet *UTHBuildPacketReal(uint8_t *payload, uint16_t payload_len,
                            uint16_t sport, uint16_t dport) {
     struct in_addr in;
 
-    Packet *p = SCMalloc(sizeof(Packet));
+    Packet *p = SCMalloc(SIZE_OF_PACKET);
     if (p == NULL)
         return NULL;
-    memset(p, 0, sizeof(Packet));
+    memset(p, 0, SIZE_OF_PACKET);
+    p->pkt = ((uint8_t *)p) + sizeof(*p);
 
     struct timeval tv;
     TimeGet(&tv);
@@ -164,7 +165,7 @@ Packet *UTHBuildPacketReal(uint8_t *payload, uint16_t payload_len,
             memset(p->udph, 0, sizeof(UDPHdr));
             p->udph->uh_sport = sport;
             p->udph->uh_dport = dport;
-            p->pktlen = sizeof(IPV4Hdr) + sizeof(UDPHdr) + payload_len;
+            SET_PKT_LEN(p, sizeof(IPV4Hdr) + sizeof(UDPHdr) + payload_len);
             break;
         case IPPROTO_TCP:
             p->tcph = SCMalloc(sizeof(TCPHdr));
@@ -173,14 +174,14 @@ Packet *UTHBuildPacketReal(uint8_t *payload, uint16_t payload_len,
             memset(p->tcph, 0, sizeof(TCPHdr));
             p->tcph->th_sport = sport;
             p->tcph->th_dport = dport;
-            p->pktlen = sizeof(IPV4Hdr) + sizeof(TCPHdr) + payload_len;
+            SET_PKT_LEN(p, sizeof(IPV4Hdr) + sizeof(TCPHdr) + payload_len);
             break;
         case IPPROTO_ICMP:
             p->icmpv4h = SCMalloc(sizeof(ICMPV4Hdr));
             if (p->icmpv4h == NULL)
                 return NULL;
             memset(p->icmpv4h, 0, sizeof(ICMPV4Hdr));
-            p->pktlen = sizeof(IPV4Hdr) + sizeof(ICMPV4Hdr) + payload_len;
+            SET_PKT_LEN(p, sizeof(IPV4Hdr) + sizeof(ICMPV4Hdr) + payload_len);
             break;
         default:
             break;
@@ -235,12 +236,12 @@ Packet **UTHBuildPacketArrayFromEth(uint8_t *raw_eth[], int *pktsize, int numpkt
 
     int i = 0;
     for (; i < numpkts; i++) {
-        p[i] = SCMalloc(sizeof(Packet));
+        p[i] = SCMalloc(SIZE_OF_PACKET);
         if (p[i] == NULL) {
             SCFree(p);
             return NULL;
         }
-        memset(p[i], 0, sizeof(Packet));
+        memset(p[i], 0, SIZE_OF_PACKET);
         DecodeEthernet(&th_v, &dtv, p[i], raw_eth[i], pktsize[i], NULL);
     }
     return p;
@@ -258,10 +259,10 @@ Packet **UTHBuildPacketArrayFromEth(uint8_t *raw_eth[], int *pktsize, int numpkt
 Packet *UTHBuildPacketFromEth(uint8_t *raw_eth, uint16_t pktsize) {
     DecodeThreadVars dtv;
     ThreadVars th_v;
-    Packet *p = SCMalloc(sizeof(Packet));
+    Packet *p = SCMalloc(SIZE_OF_PACKET);
     if (p == NULL)
         return NULL;
-    memset(p, 0, sizeof(Packet));
+    memset(p, 0, SIZE_OF_PACKET);
     memset(&dtv, 0, sizeof(DecodeThreadVars));
     memset(&th_v, 0, sizeof(th_v));
 
-- 
1.7.2.3




More information about the Oisf-devel mailing list