diff mbox

[1/2,openggsn] gtp: fix wrong binary layout for struct gtp0_header in x86_64

Message ID 1395326040-6285-1-git-send-email-pablo@gnumonks.org
State Accepted
Headers show

Commit Message

Pablo Neira Ayuso March 20, 2014, 2:33 p.m. UTC
From: Pablo Neira Ayuso <pablo@gnumonks.org>

struct gtp0_header needs __attribute__((packed)) to make sure that
gcc doesn't add a hole of 4 bytes to align the 64-bits teid, resulting
in 24 bytes instead of 20 bytes. This was breaking gtpv0 in my gprs
testbed with my x86_64 laptop.

While at it, add also attribute packed to other headers just to
make sure that gcc doesn't pad the structures with holes.
---
If no objections, I'll push this to master.

 gtp/gtp.h |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Holger Freyther March 20, 2014, 8:58 p.m. UTC | #1
On Thu, Mar 20, 2014 at 03:33:59PM +0100, pablo@gnumonks.org wrote:
> If no objections, I'll push this to master.

please go ahead. it can't hurt. Thanks for trying out v0.
diff mbox

Patch

diff --git a/gtp/gtp.h b/gtp/gtp.h
index 54af96e..39a902f 100644
--- a/gtp/gtp.h
+++ b/gtp/gtp.h
@@ -161,7 +161,7 @@  struct gtp0_header {		/*    Descriptions from 3GPP 09.60 */
 	uint8_t spare2;		/* 11 Spare */
 	uint8_t spare3;		/* 12 Spare */
 	uint64_t tid;		/* 13 Tunnel ID */
-};				/* 20 */
+} __attribute__((packed));	/* 20 */
 
 struct gtp1_header_short {	/*    Descriptions from 3GPP 29060 */
 	uint8_t flags;		/* 01 bitfield, with typical values */
@@ -174,7 +174,7 @@  struct gtp1_header_short {	/*    Descriptions from 3GPP 29060 */
 	uint8_t type;		/* 02 Message type. T-PDU = 0xff */
 	uint16_t length;	/* 03 Length (of IP packet or signalling) */
 	uint32_t tei;		/* 05 - 08 Tunnel Endpoint ID */
-};
+} __attribute__((packed));
 
 struct gtp1_header_long {	/*    Descriptions from 3GPP 29060 */
 	uint8_t flags;		/* 01 bitfield, with typical values */
@@ -190,7 +190,7 @@  struct gtp1_header_long {	/*    Descriptions from 3GPP 29060 */
 	uint16_t seq;		/* 10 Sequence Number */
 	uint8_t npdu;		/* 11 N-PDU Number */
 	uint8_t next;		/* 12 Next extension header type. Empty = 0 */
-};
+} __attribute__((packed));
 
 struct gtp0_packet {
 	struct gtp0_header h;