struct sockaddr * and alignment

Li, Qing qing.li at bluecoat.com
Tue Feb 9 18:09:03 UTC 2010


>
> Sure enough, that fixes this warning.  Yea.  But, sadly, it causes
> other problems.  If you look at sbin/atm/atmconfig/natm.c you'll see
> code like:
> 
> static void
> store_route(struct rt_msghdr *rtm)
> {
> ...
> 	char *cp
> 	struct sockaddr *sa;
> 	...
> 
> 	cp = (char *)(rtm + 1);
> ...
> 			sa = (struct sockaddr *)cp;
> 			cp += roundup(sa->sa_len, sizeof(long));
> ...
> 
> which breaks because we're now casting from an __aligned(1) char * to
> an __aligned(8) sockaddr *.

> And it is only rounding the size of the structure to long, rather than
> int64 like sockaddr_storage suggests is the proper alignment.  But I
> haven't looked in the kernel to see if there's an issue there with
> routing sockets or not.
> 

In the kernel route.h, the macro SA_SIZE is used by the routing socket
code and may the root of the problem.

-- Qing





More information about the freebsd-net mailing list