Hi ML,

I noticed that also the others headers structs have the same potential 
problem.
I attached the patch to fix the net.h header file.

best regards,

luigi

On Tuesday 27 January 2009 19:32:10 Luigi 'Comio' Mantellini wrote:
> Hi ML,
>
> I'm working on a mips target and I used qemu_mips target to simulate my
> target (that I hope to have in the next week...)
>
> Following my activities I noticed that IP_t structure is no defined with
> attribute "packed". I noticed this issue because using a self-made
> toolchain (gcc4.2.4+binutils2.8+uclibc0.9.30) the compiler has aligned all
> bytes to 32bit boundary. This is not ok, because the packets IP_t can be
> non aligned (see the /net/net.c PingSend function, for an example).
>
> The dirty solution is to define the structure with the
> __attribute__((__packed__))... but, from my point of view, a better packet
> forging mechanism should be implemented into the net.c stack.
>
> I attached a trivial patch that solved the issue on my target.
>
> Any comments is welcome.
>
> best regards,
>
> luigi

-- 
Luigi Mantellini
R&D - Software
Industrie Dial Face S.p.A.
Via Canzo, 4
20068 Peschiera Borromeo (MI), Italy
Tel.:  +39 02 5167 2813
Fax:   +39 02 5167 2459
Email: luigi.mantell...@idf-hit.com

diff --git a/include/net.h b/include/net.h
index d2d394f..f14df6c 100644
--- a/include/net.h
+++ b/include/net.h
@@ -154,7 +154,7 @@ typedef struct {
 	uchar		et_snap2;
 	uchar		et_snap3;
 	ushort		et_prot;	/* 802 protocol			*/
-} Ethernet_t;
+} __attribute__((__packed__)) Ethernet_t;
 
 #define ETHER_HDR_SIZE	14		/* Ethernet header size		*/
 #define E802_HDR_SIZE	22		/* 802 ethernet header size	*/
@@ -168,7 +168,7 @@ typedef struct {
 	ushort		vet_vlan_type;	/* PROT_VLAN			*/
 	ushort		vet_tag;	/* TAG of VLAN			*/
 	ushort		vet_type;	/* protocol type		*/
-} VLAN_Ethernet_t;
+} __attribute__((__packed__)) VLAN_Ethernet_t;
 
 #define VLAN_ETHER_HDR_SIZE	18	/* VLAN Ethernet header size	*/
 
@@ -198,7 +198,7 @@ typedef struct {
 	ushort		udp_dst;	/* UDP destination port		*/
 	ushort		udp_len;	/* Length of UDP packet		*/
 	ushort		udp_xsum;	/* Checksum			*/
-} IP_t;
+} __attribute__((__packed__)) IP_t;
 
 #define IP_OFFS		0x1fff /* ip offset *= 8 */
 #define IP_FLAGS	0xe000 /* first 3 bits */
@@ -239,7 +239,7 @@ typedef struct
 	uchar		ar_tha[];	/* Target hardware address	*/
 	uchar		ar_tpa[];	/* Target protocol address	*/
 #endif /* 0 */
-} ARP_t;
+} __attribute__((__packed__)) ARP_t;
 
 #define ARP_HDR_SIZE	(8+20)		/* Size assuming ethernet	*/
 
@@ -269,7 +269,7 @@ typedef struct icmphdr {
 			ushort	mtu;
 		} frag;
 	} un;
-} ICMP_t;
+} __attribute__((__packed__)) ICMP_t;
 
 
 /*
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to