[mc1322x] Non-aligned structure copies
Jon Smirl
jonsmirl at gmail.com
Tue Nov 3 22:48:43 EST 2009
My TTL field was getting stomped in the packets so I added some debug
uip_nd6_io_rs_output(void) {
UIP_IP_BUF->vtc = 0x60;
UIP_IP_BUF->tcflow = 0;
UIP_IP_BUF->flow = 0;
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
UIP_IP_BUF->ttl = UIP_ND6_HOP_LIMIT;
printf("ttl 1 %d\n", UIP_IP_BUF->ttl);
uip_create_linklocal_allrouters_mcast(&UIP_IP_BUF->destipaddr);
printf("ttl 2 %d %p %p\n", UIP_IP_BUF->ttl, &UIP_IP_BUF->ttl,
&UIP_IP_BUF->srcipaddr);
uip_netif_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
printf("ttl 3 %d\n", UIP_IP_BUF->ttl);
The select_src(... was stomping TTL
More debug and I track it down to ipaddr_copy...
printf("uip_netif_select_src %d %d\n", best, index);
uip_ipaddr_copy(src, &(uip_netif_physical_if.addresses[index].ipaddr));
return;
--- It's doing a struct copy. I'm suspicious about non-aligned access on ARM
#ifndef uip_ipaddr_copy
#define uip_ipaddr_copy(dest, src) (*(dest) = *(src))
#endif
I change it to:
#ifndef uip_ipaddr_copy
//#define uip_ipaddr_copy(dest, src) (*(dest) = *(src))
#define uip_ipaddr_copy(dest, src) \
{ \
int i; \
for (i = 0; i < sizeof *(dest); i++) { \
*(((char *)(dest)) + i) = *(( (char *)(src)) + i); \
} \
}
#endif
--- TTL doesn't get stomped any more
Sending NS to ff00:0000:0000:0000:0000:0001:ffff:ee00 from
0000:0000:0000:0000:0000:0000:0000:0000 with target address
fe80:0000:0000:0000:dfcc:bbaa:aa99:ffee
output;
Sending RS 0
ttl 1 255
ttl 2 255 40e59a 40e59b
uip_netif_select_src
uip_netif_select_src 0 0
ttl 3 255
ttl 4 255
The code still doesn't work because there are more of these floating around.
Is there some compiler switch to tell it to do the right thing with an
unaligned struct copy?
--
Jon Smirl
jonsmirl at gmail.com
More information about the mc1322x
mailing list