Re: spread-5.0.0rc1 : Solaris setsockopt issue

"Daniel F. Savarese" <[email protected]> Tue, 10 Jan 2017 15:15:07 -0500
Newsgroups gmane.network.spread.user
Message-ID <[email protected]>
In message <CAOSQKUU4jZqLc5dCdp=eQibVsPAXDHHCrqpirTvmE9Y-mieGeg@mail.gmail.com>
, Martin Schu writes:
>at Solaris. On the other hand the new code is running well at both Solaris
>and Linux. So there is no need to make it OS dependent.

I would caution against assuming the changes for the non-int options will
just work everywhere.  They may happen to work (or rather, not fail)
depending on the endianness of a system or the robustness of the underlying
setsockopt implementation, but may not necessarily set the desired value.
In fact, setsockopt should be failing with EINVAL on Linux (or at least the
4.1.x kernels) for IPV6_MULTICAST_HOPS and IPV6_MULTICAST_LOOP.  My guess
is you only tested IPv4.  These are the type values for the non-int options
on OSes I could verify:

Linux (verified by ip(7) and ipv6(7) man pages and ip_sockglue.c and
ipv6_sockglue.c from 4.1.37 kernel source):

IP_MULTICAST_TTL    int expected but unsigned char tolerated by implementation
IP_MULTICAST_LOOP   int expected but unsigned char tolerated by implementation
IPV6_MULTICAST_HOPS int expected; errno set to EINVAL if optlen < sizeof(int)
IPV6_MULTICAST_LOOP int expected; errno set to EINVAL if optlen < sizeof(int)

FreeBSD (verified by ip(4) and ip(6) man pages and in_mcast.c and in6_mcast.c
from FreeBSD 10.3 kernel source):

IP_MULTICAST_TTL    unsigned char expected; unsigned int tolerated by
                    implementation and int should also work for value range
IP_MULTICAST_LOOP   unsigned char expected; unsigned int tolerated by
                    implementation and int should also work for value range
IPV6_MULTICAST_HOPS int; errno set to EINVAL if optlen != sizeof(int)
IPV6_MULTICAST_LOOP unsigned int; int should also work; errno set to EINVAL
                    if optlen != sizeof(unsigned int)

Solaris (verified only by ip(7P) and ip6(7P) man pages):

IP_MULTICAST_TTL    unsigned char
IP_MULTICAST_LOOP   unsigned char
IPV6_MULTICAST_HOPS int
IPV6_MULTICAST_LOOP unsigned char

The end result is that it's safe to use int, but not unsigned char,
for all of the options on Linux and FreeBSD.  Solaris needs special-casing
for unsigned char.

Daniel