[U-Boot] IP_t should be a "packed" struct

Ben Warren biggerbadderben at gmail.com
Wed Jan 28 22:52:15 CET 2009


Wolfgang Denk wrote:
> Dear Ben Warren,
>
> In message <4980CC59.1070302 at gmail.com> you wrote:
>   
>>> My idea should be to declare a define like this
>>>
>>> #define PKT_HEADER __attribute__((__packed__))
>>>
>>> my 2EuroCents.
>>>
>>> best regards,
>>>
>>> luigi
>>>
>>>   
>>>       
>> OK, sounds good.  Send a patch please.
>>     
>
> Hm... and what does this give us?
>
> How long  until  sombebody  detects  that  all  the  data  structures
> describing  device  register  layout  or so many processors and chips
> don't use any __packed__ either? Except for some (IMHO broken, but  I
> know  that  I'm  more  attached  to PowerPC anyway) ARM systems it is
> sufficient to use a "sane" selection of data types.
>
>
>   
Well, yeah, I alluded to that in my other e-mail.  I'm not crazy about 
this either, but don't see any significant downside.  Obviously if this 
was a common problem, it would have surfaced a long time ago...
> I vote against changing this code. Just for a quick  cross-check:  do
> the   corresponding   data  structs  in  the  Linux  kernel  use  any
> __packed__?
>
> Here is for example a copy of /usr/include/netinet/ip.h :
>
> ...
> struct iphdr
>   {
> #if __BYTE_ORDER == __LITTLE_ENDIAN
>     unsigned int ihl:4;
>     unsigned int version:4;
> #elif __BYTE_ORDER == __BIG_ENDIAN
>     unsigned int version:4;
>     unsigned int ihl:4;
> #else
> # error	"Please fix <bits/endian.h>"
> #endif
>     u_int8_t tos;
>     u_int16_t tot_len;
>     u_int16_t id;
>     u_int16_t frag_off;
>     u_int8_t ttl;
>     u_int8_t protocol;
>     u_int16_t check;
>     u_int32_t saddr;
>     u_int32_t daddr;
>     /*The options start here. */
>   };
> ...
>
> Do you see any __packed__?
>
>   
Yeah, I made the same observation, but am not fluent enough in the black 
magic of Linux header files to know if packing was being enforced 
somewhere else or in some other way that my little brain can't comprehend.
> Best regards,
>
> Wolfgang Denk
>
>   
regards,
Ben


More information about the U-Boot mailing list