From ff4323418bf46b3dfb4d744d5626e2aa09935c98 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Fri, 1 Dec 2006 17:50:11 +0000 Subject: [PATCH] Move the __packed declarations. This makes sizeof(struct llc) 8 again on the arm. Add an assert to ensure that the size is 8 to prefent others from falling into this trap (we should have more of these). Why the construct: struct foo { union bar { struct { ... } __packed fred; ... } __packed wilma; } __packed; has a different packing than: struct foo { union bar { struct { ... } fred __packed; ... } wilma __packed; } __packed; is beyond my ability to ferret out of the gcc documentation. Most likely some subtle binding issue (eg before it says the struct itself is packed, while after it means that the whole struct is packed into the thing it is in). Pointers to relevant documentation would be appreciated. --- sys/net/if_llc.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/sys/net/if_llc.h b/sys/net/if_llc.h index 8d96686c0aac..0d96372ed5be 100644 --- a/sys/net/if_llc.h +++ b/sys/net/if_llc.h @@ -52,15 +52,15 @@ struct llc { u_int8_t format_id; u_int8_t class; u_int8_t window_x2; - } type_u __packed; + } __packed type_u; struct { u_int8_t num_snd_x2; u_int8_t num_rcv_x2; - } type_i __packed; + } __packed type_i; struct { u_int8_t control; u_int8_t num_rcv_x2; - } type_s __packed; + } __packed type_s; struct { u_int8_t control; /* @@ -72,17 +72,17 @@ struct llc { u_int8_t frmr_control; u_int8_t frmr_control_ext; u_int8_t frmr_cause; - } type_frmr __packed; + } __packed type_frmr; struct { u_int8_t control; u_int8_t org_code[3]; u_int16_t ether_type; - } type_snap __packed; + } __packed type_snap; struct { u_int8_t control; u_int8_t control_ext; - } type_raw __packed; - } llc_un /* XXX __packed ??? */; + } __packed type_raw; + } __packed llc_un; } __packed; struct frmrinfo { @@ -114,6 +114,10 @@ struct frmrinfo { #define LLC_FRMRLEN 7 #define LLC_SNAPFRAMELEN 8 +#ifdef CTASSERT +CTASSERT(sizeof (struct llc) == LLC_SNAPFRAMELEN); +#endif + /* * Unnumbered LLC format commands */