lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [lwip-users] Struct packing/alignment problems


From: Mountifield, Tony
Subject: RE: [lwip-users] Struct packing/alignment problems
Date: Tue, 27 Apr 2004 16:34:46 +0100

OK, I have made a formal patch for this and submitted it to the Bug Tracker on 
Savannah (bug #8708). I forgot to log in first, so it says it's from "None". Is 
there any way to recover from that?

Here is the text from the bug report:

--START--
On 32-bit processors that cannot do unaligned accesses, there are problems with 
32-bit values in the IP and TCP headers, due to their being preceded by an 
ethernet header of 14 bytes.

This patch (against CVS as at 27-Apr-04) overcomes this problem by optionally 
putting two bytes of padding at the beginning of the Ethernet header. This 
makes the Ethernet header 16 bytes long, and the transferring of data to or 
from the Ethernet chip starts two bytes into the buffer. Thanks to Timmy Brolin 
for the original suggestion.

Some comments on the patch:

ip_addr.h: A new struct ip_addr2 is defined for use in the ARP packets. 
Depending on the amount of padding, either dipaddr or sipaddr will be 
unaligned. ip_addr2 contains a two-element 16-bit array, addrw[2]. There is 
only one place where this field must be accessed by name.

etharp.h: PAD_ETH_SIZE is normally defined as 2. If it is undefined or zero, 
the adjustments are not performed (but struct ip_addr2 is still used)

etharp.c: The test for 0.0.0.0 is the only place where addrw[] is used. The 
various assigments of IP addresses are performed using structure copies 
instead, with pointer casts where necessary to change between struct ip_addr 
and struct ip_addr2. Address compatison is performed using memcmp().

ethernetif.c: As this template is now up-to-date with etharp, it shows the 
modifications required in an ethernet driver to support PAD_ETH_SIZE. 
pbuf_header() is used to drop and regain the two bytes padding for eas of 
transferring to and from the chip. In low_level_input(), the allocated pbuf 
must allow for PAD_ETH_SIZE. The call to pbuf_header in case ETHTYPE_IP must 
use -sizeof(struct eth_hdr) instead of just -14.
--END--

Cheers,
Tony

> -----Original Message-----
> From: K.J. Mansley [mailto:address@hidden
> Sent: 27 April 2004 08:54
> To: Mailing list for lwIP users
> Subject: Re: [lwip-users] Struct packing/alignment problems
> 
> 
> On Tue, 2004-04-27 at 00:58, Timmy Brolin wrote:
> > Putting 
> > a 16bit pad in the very beginning of the Ethernet header is 
> probably the 
> > solution to this.
> 
> I thought we already did this (although it will be netif 
> driver specific
> I guess, so some of them might not).  Putting padding between the
> ethernet and IP headers would, as you explained, be troublesome.
> 
> > >I implemented some of what needs to be done and found it fairly
> > >straight-forward.
> > >
> > It is not that hard to patch it up to work, no. It is a 
> little harder to 
> > make it work without ugly patches such as data rearrangement and 
> > decreased performance.
> 
> Yes.
> 
> Kieran
> 
> 
> 
> _______________________________________________
> lwip-users mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/lwip-users
> 


***********************************************************************************
This email, its content and any attachments is PRIVATE AND
CONFIDENTIAL to TANDBERG Television. If received in error please
notify the sender and destroy the original message and attachments.

www.tandbergtv.com
***********************************************************************************





reply via email to

[Prev in Thread] Current Thread [Next in Thread]