ralphjzhang / openpgm

Automatically exported from code.google.com/p/openpgm
0 stars 0 forks source link

HAVE_HOST_ORDER_IP_* header byte order config options detected incorrectly #27

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
HAVE_HOST_ORDER_IP_LEN and HAVE_HOST_ORDER_IP_OFF used in packet_parse.c are 
not detected correctly.  This may vary based on version, packaging, or 
configure vs. scons.  

For example:

=========
root@pgm-test-1:~/libpgm-5.1.118-1~dfsg/openpgm/pgm# ./configure | grep 'host 
byte'
checking for raw IP sockets ip_{len,off} host byte ordering... no

root@pgm-test-1:~/libpgm-5.2.122/openpgm/pgm# ./configure | grep 'host byte'
checking for raw IP sockets ip_{len,off} host byte ordering... no

root@pgm-test-1:~/libpgm-5.2.122/openpgm/pgm# scons WITH_GLIB=true 
WITH_GETTEXT=true 2>&1 | egrep '(HAVE_HOST|host byte)'
Checking for raw IP sockets ip_{len,off} host byte ordering...yes
Checking for raw IP sockets ip_{len,off} host byte ordering...yes

root@pgm-test-1:~/openpgm-read-only/openpgm/pgm# scons WITH_GLIB=true 
WITH_GETTEXT=true 2>&1 | grep 'host byte'
Checking for raw IP sockets ip_{len,off} host byte ordering...yes
Checking for raw IP sockets ip_{len,off} host byte ordering...yes
=========

When built on my systems using scons, I can not send and receive using 
pgmsend/pgmrecv.

Platforms:

=========
Linux pgm-test-1 3.5.0-26-generic #42~precise1-Ubuntu SMP Mon Mar 11 22:19:42 
UTC 2013 i686 i686 i386 GNU/Linux

Linux pgm-test-0 3.2.0-39-generic #62-Ubuntu SMP Thu Feb 28 00:28:53 UTC 2013 
x86_64 x86_64 x86_64 GNU/Linux
=========

When running with debug logging on, this is printed:

=========
2013-04-07 01:24:45 pgm-test-1 Pgm: Debug: pgm_parse_raw (skb:0x872fb38 
dst:0xb7292c3c error:0xb729278c)
2013-04-07 01:24:45 pgm-test-1 Pgm: Trace: Discarded invalid packet: IP packet 
received at 64 bytes whilst IP header reports 16384 bytes.
2013-04-07 01:24:45 pgm-test-1 Pgm: Debug: recvskb (sock:0x872e1a8 
skb:0x872fb38 flags:0 src-addr:0xb7292bbc src-addrlen:128 dst-addr:0xb7292c3c 
dst-addrlen:128)
=========

This looked odd, and I suspected a byte ordering issue.  An analysis of the 
code shows two #ifdefs around these config options that toggle the use of 
ntohs().  Their origin is traced back to SConscript.autoconf:

=========
# IP header order as per IP(4) on FreeBSD
def CheckIpLengthHostOrder (context):
        context.Message ('Checking for raw IP sockets ip_{len,off} host byte ordering...');
        source = """
int
main ()
{
#if defined( __APPLE__ ) || defined( __NetBSD__ ) || defined( __FreeBSD__ )
        fail fail fail
#endif
        return 0;
}
        """
        result = context.TryCompile (source, '.c');
        context.Result (result);
        return result;

def CheckIpOffsetHostOrder (context):
        return CheckIpLengthHostOrder (context);
=========

This appears to simply be platform define-based.  I don't think this is 
correct, because when I make the check fail for my platform, recompile with 
scons, and rerun my test it works correctly:

=========
2013-04-07 01:29:06 pgm-test-1 Pgm: Trace: Recv again on not-full
2013-04-07 01:29:06 pgm-test-1 Pgm: Debug: recvskb (sock:0x9c581a8 
skb:0xb6901648 flags:0 src-addr:0xb7233bbc src-addrlen:128 dst-addr:0xb7233c3c 
dst-addrlen:128)
2013-04-07 01:29:06 pgm-test-1: (12 bytes)
2013-04-07 01:29:06 pgm-test-1:     0: "please work" (12 bytes from 
133.21.200.234.76.178.34920)
2013-04-07 01:29:06 pgm-test-1 Pgm: Debug: pgm_recvmsgv (sock:0x9c581a8 
msg-start:0xb7233cf0 msg-len:20 flags:0 bytes-read:0xb72342f4 error:0xb72342f8)
2013-04-07 01:29:06 pgm-test-1 Pgm: Debug: recvskb (sock:0x9c581a8 
skb:0xb6901648 flags:0 src-addr:0xb7233bbc src-addrlen:128 dst-addr:0xb7233c3c 
dst-addrlen:128)
=========

I believe this check needs to be fixed.

Original issue reported on code.google.com by kyle.a.g...@gmail.com on 7 Apr 2013 at 5:34

GoogleCodeExporter commented 9 years ago
Correct, the check is implemented as the most convenient method and ignores 
that Linux can run on both little and big endian hardware.

Original comment by fnjo...@gmail.com on 7 Apr 2013 at 1:58

GoogleCodeExporter commented 9 years ago
Any way to at least make compilation fail with a "put your endian-ness here" 
error?  It looks like #error won't do it in scons.

Original comment by kyle.a.g...@gmail.com on 7 Apr 2013 at 7:33

GoogleCodeExporter commented 9 years ago
I have to think about this: this question isn't about endianess it is about 
BSD's really weird IP stack:  It cannot be detected conveniently, it is by 
platform.

Scons is detecting network byte order, the inverse of Autoconf.  Thus a 
reasonable change would be:

#if defined( __APPLE__ ) || defined( __NetBSD__ ) || defined( __FreeBSD__ )
        return 0;
#else
        fail fail fail
#endif

Original comment by fnjo...@gmail.com on 7 Apr 2013 at 10:49

GoogleCodeExporter commented 9 years ago
Confirmed fixed in r1508.

Original comment by fnjo...@gmail.com on 20 Feb 2014 at 2:28