Re: [Etherboot-developers] bootp_t alignment problem
Brought to you by:
marty_connor,
stefanhajnoczi
|
From: <ke...@us...> - 2003-05-02 11:38:50
|
>bootpreply = (struct bootp_t *)&nic.packet[ETH_HLEN + sizeof(struct iphdr)
>+ sizeof(struct udphdr)];
>
>how this alignment problem can be taken care of..I was using in header
>file,
>struct bootp_t __attribute__ ((aligned(4)))
>without any difference.
This one is a nasty one, you've found an alignment bug. The IP and UDP
headers are multiples of 4 but ETH_HLEN is 14. Declaring bootp_t
aligned does no good because that only aligns instances of bootp_t, not
buffers that have been cast to bootp_t. To fix this will require a copy
of the packet, instead of a cast. To avoid having to allocate another
1.5kB buffer statically or on the stack, you can move this memcpy:
memcpy((char *)BOOTP_DATA_ADDR, (char *)bootpreply, sizeof(struct bootpd_t));
up just after the test for packet length, changing it to:
memcpy((char *)BOOTP_DATA_ADDR, nic.packet, sizeof(struct bootpd_t));
then assign bootpreply:
bootpreply = (struct bootp_t *)BOOTP_DATA_ADDR;
Thanks for finding this alignment bug and the endian bugs. Obviously
we've been spoiled by running on little endian and u16 alignment
machines.
Robb Main is hacking nic.c at the moment so you should probably let him
make this fix.
|