From: Laszlo Valko <valko@linux.karinthy.hu>
To: Thomas Heinz <creatix@hipac.org>
Cc: netfilter-devel@lists.netfilter.org
Subject: Re: Comments about IPT_ALIGN
Date: Sun, 26 Jan 2003 12:01:59 +0100 [thread overview]
Message-ID: <20030126120159.A3045@linux.karinthy.hu> (raw)
In-Reply-To: <3E335CB1.9070101@hipac.org>; from creatix@hipac.org on Sun, Jan 26, 2003 at 04:57:37AM +0100
On Sun, Jan 26, 2003 at 04:57:37AM +0100, Thomas Heinz wrote:
> Conclusions:
>
> Except for struct tptr both sparc64 and alpha have the same struct
> alignment and member offsets for all structs.
This is not too surprising. Both of them are RISC processors with
strict alignment restrictions. I guess even with a 32bit sparc
gcc, a 64bit unsigned integer gets aligned to 64bit just to make life
easier (I'm not sure if there's a 64bit load instruction on 32bit sparc's).
> struct tptr is different because sizeof(void *) is different on alpha
> and sparc64 (in user space).
>
> Now, imagine that only those structs were allowed for which the
> following properties hold:
> - basic datatype must be of fixed width (e.g. __u8, __u16,
> __u32, __u64)
> - members of the struct can be of:
> * basic type
> * array of basic type
> * array of struct (for which the same properties hold)
> * struct (for which the same properties hold)
>
> In this case the IPT_ALIGN macro is _not_ needed!
>
> So I come to the conclusion that if no pointers within target or match
> structs would be needed IPT_ALIGN can be dropped without any
> problems (if the assumption about the basic datatype holds).
>
> What do you think about this? Am I wrong/right? Do I miss anything?
> Is the stuff stated above trivially obvious ;-)?
You missed one point (currently (ab)used by netfilter):
* structures which are "put" next to each other (eg: ipt_replace and
ipt_entry) must be examined carefully for alignment problems.
Otherwise you are right.
But this "put" next to each other thing can be rather nasty.
You can be sure a structure is padded at the end by the compiler to
whatever alignment is necessary for that structure. So if you have
a 64bit integer in it, it will be padded at the end to 64bit. To
ensure that arrays of that structure work.
Now the problem comes if you have only 32bit integers in the first
structure and 64bit integers in the second one: you have to either
use IPT_ALIGN again (which we would like to get rid of), or we
have to make sure the first structure gets aligned to 64bit.
We could introduce an extra variablke just for this at the end
like:
u_int64_t dummy[0];
}
Or we could do something like that in netfilter:
struct ipt_entry entries[0];
}
This latter version is better if we know what kind structure will follow,
because it will not increase the size of the structure unnecessarily on
platforms without alignment restrictions.
Regards,
Laszlo
next prev parent reply other threads:[~2003-01-26 11:01 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-26 3:57 Comments about IPT_ALIGN Thomas Heinz
2003-01-26 11:01 ` Laszlo Valko [this message]
2003-01-26 11:28 ` Anders Fugmann
2003-01-26 13:58 ` Thomas Heinz
2003-01-26 14:26 ` Laszlo Valko
2003-01-26 16:50 ` Thomas Heinz
2003-01-26 19:31 ` Laszlo Valko
2003-01-31 11:51 ` Harald Welte
2003-01-26 14:22 ` Laszlo Valko
2003-01-26 18:05 ` Thomas Heinz
2003-01-26 19:43 ` Laszlo Valko
2003-01-26 23:09 ` Thomas Heinz
2003-01-27 0:43 ` Laszlo Valko
2003-01-27 10:33 ` Thomas Heinz
2003-01-31 11:57 ` Harald Welte
2003-01-26 19:48 ` Thomas Heinz
2003-01-31 11:55 ` Harald Welte
2003-01-31 23:37 ` Laszlo Valko
2003-01-26 17:06 ` Thomas Heinz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030126120159.A3045@linux.karinthy.hu \
--to=valko@linux.karinthy.hu \
--cc=creatix@hipac.org \
--cc=netfilter-devel@lists.netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.