Subject: Re: ip_nat MSS clamping
To: Martin Husemann <martin@duskware.de>
From: Robert Elz <kre@munnari.OZ.AU>
List: tech-net
Date: 06/05/2002 17:35:02
    Date:        Mon, 3 Jun 2002 20:40:28 +0200
    From:        Martin Husemann <martin@duskware.de>
    Message-ID:  <20020603204028.I403@night-porter.duskware.de>

  | > This is quite dangerous construction for any platform with strict
  | > alignment.
  | 
  | True.

I know it has been committed this (general) way now (with just some var
named changed), and what is there is safe, but it really is way overkill... 

  | +				memcpy(&netmss, &cp[2], 2);
  | +				mss = (uint32_t)ntohs(netmss);

which really can just be

				mss = (cp[2] << 8) | cp[3];

We know what is there is network byte order, we know what that is,
and we know it isn't going to change, simply fetching the bytes and
constructing the integral value using the definition of what's in the
data stream is perfectly safe, portable, and all that...

Similarly:

  | +					netmss = htons((short)(maxmss));
  | +					memcpy(&cp[2], &netmss, 2);

					cp[2] = maxmss >> 8;
					cp[3] = maxmss /* & 0xFF */ ;

Save the function call, and allow the compiler to to a better job
(on a big endian system without alignment issues, a smart compiler could
simply do the 2 byte fetch/store after noticing what the code is doing).

kre