Tue 27 Apr 2004 03:33:10 PM UTC, original submission:
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.
|