Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 4 Aug 2001 12:23:04 +1000 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Brian Somers <brian@Awfulhak.org>
Cc:        Julian Elischer <julian@elischer.org>, Thomas Pornin <Thomas.Pornin@ens.fr>, <freebsd-net@FreeBSD.ORG>, <freebsd-alpha@FreeBSD.ORG>, Brian Somers <brian@freebsd-services.com>, <FreeBSD-gnats-submit@FreeBSD.ORG>, Brian Somers <brian@freebsd-services.com>
Subject:   Re: kern/27767: (was: PPPoE + Alpha + 32/64 bits) 
Message-ID:  <20010804121134.G16179-100000@besplex.bde.org>
In-Reply-To: <200108022338.f72Nc6u09427@hak.lan.Awfulhak.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 3 Aug 2001, Brian Somers wrote:

> > [bde wrote]
> > Here I don't see how packing the struct helps on alphas.  Doesn't it
> > cause traps by misaligning uniqtag.data.pointer?  I think you need
> > something like:
>
> It doesn't cause a trap as the compiler is (now) smart enough to
> handle it properly.  Note where we have the alignment problem here:

I guess it knows how to handle this in packed structs and not in many
other cases.

> >   	struct {
> > 		struct	pppoe_tag hdr;
> >  		char	data[sizeof(void *)];
> > 	} uniqtag;
> > 	void *pointer;
> > 	...
> > 	pointer = sp;
> > 	memcpy(uniqtag.data, &pointer, sizeof(uniqtag.data));
>
> That's probably better.  I went with the __attribute((packed)) stuff
> because it was already done that way in the rest of the code.

I think the packed attributes in ng_pppoe.h are no-ops on most machines.

> In this specific case however, it may be best to just send the variable
> plus the alignment padding as the tag:
>
>         struct {
>                 struct pppoe_tag hdr;
>                 union   uniq    data;
>         } uniqtag;
>
>         ......
>         uniqtag.hdr.tag_type = PTT_HOST_UNIQ;
>         uniqtag.hdr.tag_len = htons((u_int16_t)(sizeof(uniqtag) - sizeof(uniqtag.hdr));
>         uniqtag.data.pointer = sp;

You might also have to zero everything to ensure that there is no stack
garbage in the message.

Bruce


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010804121134.G16179-100000>