Subject: Re: Explicit packing in
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: B. James Phillippe \(nospam address\) <>
List: tech-net
Date: 01/21/2002 13:13:19
On the cold day of Jan 21, der Mouse mused:

> > I am curious to know why <netinet/ip.h> explicitly packs "struct ip" in
> > NetBSD (BTW, I'm on NetBSD-1.5.2/alpha).  None of the other UNIX
> > systems I have access to* do this, and I would not think it necessary.
> It appears - to me - to be not for the sake of structure packing but
> rather for the sake of declaring it possibly misaligned.

Right, since the definition of an IP header (all of them) is inherently

> > But would this not also cause the compiler to possibly generate fixups
> > where they are not needed as well?
> Yes.  In many (most?) uses of struct ip, the compiler can't know whether
> the struct is aligned until run-time (because it's overlaid onto memory
> obtained from elsewhere, such as an mbuf).

Okay, so now that I have an agreeing expert, :-) I can pose the question of
whether this will have a needless performance impact on the networking

Particulary on systems where unaligned fixups are expensive, like Alpha.
This of course assumes that the IP structures are almost always aligned
properly - I am still a newbie with NetBSD, but from looking at the if_de.c
ethernet driver, it does appear to be the case that, as in Linux, the
driver shifts the IP header up by 2 bytes to account for the 14-byte
ethernet header.

# bryan at darkforest dot org
# Software Architect