From: Ken Steele Date: Fri, 20 Dec 2013 16:52:12 +0000 (-0500) Subject: Add Packed attribute on Header structures X-Git-Tag: suricata-2.1beta1~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=045966676dd3c4b8de041d11f8ce11d814dd52f7;p=thirdparty%2Fsuricata.git Add Packed attribute on Header structures Structures that are used to cast packet data into fields need to be packed so that the compiler doesn't add any padding to these fields. This also helps Tile-Gx to avoid unaligned loads because the compiler will insert code to handle the possible unaligned load. --- diff --git a/src/app-layer-dns-common.h b/src/app-layer-dns-common.h index 9ae04c165d..ab2d8ef118 100644 --- a/src/app-layer-dns-common.h +++ b/src/app-layer-dns-common.h @@ -78,12 +78,12 @@ typedef struct DNSHeader_ { uint16_t answer_rr; uint16_t authority_rr; uint16_t additional_rr; -} DNSHeader; +} __attribute__((__packed__)) DNSHeader; typedef struct DNSQueryTrailer_ { uint16_t type; uint16_t class; -} DNSQueryTrailer; +} __attribute__((__packed__)) DNSQueryTrailer; /** \brief DNS answer header * packed as we don't want alignment to mess up sizeof() */ diff --git a/src/decode-tcp.h b/src/decode-tcp.h index 067d4a4862..152d5103f4 100644 --- a/src/decode-tcp.h +++ b/src/decode-tcp.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2013 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -136,7 +136,7 @@ typedef struct TCPHdr_ uint16_t th_win; /**< pkt window */ uint16_t th_sum; /**< checksum */ uint16_t th_urp; /**< urgent pointer */ -} TCPHdr; +} __attribute__((__packed__)) TCPHdr; typedef struct TCPVars_ { diff --git a/src/decode-udp.h b/src/decode-udp.h index 2c3a7845d7..5636c32b0f 100644 --- a/src/decode-udp.h +++ b/src/decode-udp.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2013 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -42,7 +42,7 @@ typedef struct UDPHdr_ uint16_t uh_dport; /* destination port */ uint16_t uh_len; /* length */ uint16_t uh_sum; /* checksum */ -} UDPHdr; +} __attribute__((__packed__)) UDPHdr; typedef struct UDPVars_ {